Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Why am I getting this error? Error: expected declaration specifiers or '...' before string constant| in c code

What I have tried:

c
Why am I getting this error? Error: expected declaration specifiers or '...' before string constant| in c code 
Posted
Updated 27-Jun-22 8:16am
Comments
k5054 30-Nov-19 7:25am    
You will need to add some context. Show the code - or at least enough of it so we can see what might be generating the error. What you've given us is like texting the doctor "it hurts when I do this"....

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.

But ... at a guess, you are either missing a semicolon, or have an extra close curly bracket.

Look at the line it reports the error on, and see what it actually is. (The compiler error message will tell you which file and line it found it on). You may also need to look at the lines immediately above that one as well, because compilers aren't that bright (especially C compilers which are generally all written in the last century: C is not a "modern language" anymore).

If you can't work it out, you'll need to show us the line, the dozen lines above and below it, and the full text of the error message.
 
Share this answer
 
v2
Quote:
Why am I getting this error?

Because you have an error in your code before the position of error message.
Correction depend on your code which you kept secret.
 
Share this answer
 
I had the same problem. My error messages were:

TarHeader.h:15:24: error: expected declaration specifiers or '...' before numeric constant
TarHeader.c:69:61: error: expected declaration specifiers or '...' before string constant


And the specific lines of code were:

* Line 15 in TarHeader.h:
C
#define TAR_BLOCK_SIZE 512


* Line 69 (v1) in TarHeader.c:
C
static_assert(TAR_BLOCK_SIZE == sizeof(tar_posix_header_t), "Incorrect header definition");


When I tried to change it I changed the includes in "TarHeader.c" (removed include of "TarHeader.h")
The line seems then like this (Line 69 (v2) in TarHeader.c)
C
static_assert(512== sizeof(tar_posix_header_t), "Incorrect header definition");


And the error codes changed:

TarHeader.c:69:15: error: expected declaration specifiers or '...' before numeric constant
TarHeader.c:69:50: error: expected declaration specifiers or '...' before string constant


When I removed line 65 of "TarHeader.c" no error was reported even with the previously used include.

The static assert was copied from another project (also in C) ane there was no problem. But it was a different compiler.

Solution:

Search for the use of these defines and see what use causes this problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900