92
votes

I have a C code written. When I compile it on Linux then in the header file it says the following error: storage class specified for parameter i32 , i8 and so on

typedef int i32;

typedef char    i8;
8
You'll need to show a bit more code.Marcelo Cantos
poor question, should be updated with the actual bad code..RushPL
Why are you all criticising? If the person knew where exactly is the problem, they would have fixed it, instead of posting the snippet. Or do you want 10 kLOC pasted? The question is upvoted, because it is a common and arcane problem with a good accepted answer.Vorac
I got this eror when I was daydreaming and declared a memebr function as extern in the class definition (slides off sheepishly, cheeks aflame)Mawg says reinstate Monica

8 Answers

311
votes

Chances are you've forgotten a semicolon in a header file someplace. Make sure each line ends in ;

20
votes

i had the same experience. The problem was at the function prototype declaration in the header file where a semi colon was missing at the end of function declaration.

The function was indicated in the compilation logs as "In function ... " just before the error snippet

Hope this helps!!

18
votes

You have some code somewhere, probably indicated in the full text of the error message, that does something like this:

void function(static int foo)

The static is not allowed there. It could also be another storage class, like register or extern.

6
votes

I incurred this same error once. The solution was to browse around files and look for pending statements (like a non-closed parenthesis, or a missing semicolon.) Usually it's really a trivial error, but the compiler complains.

The bad news is that it doesn't always complain at the right line (or even in the right file!) The good news is that in these cases it says something useful like:

WRONGFILE.h: In function ‘FUNCTION_OF_ANOTHER_FILE_WRT_WRONG_FILE’"
WRONGFILE:line:col: error: storage class specified for parameter ‘param’ before. 

Go and check in that other reported file.

1
votes

To add up on ;: another case can be a missing ) in a function pointer declaration:

extern void init_callbacks(void (*init)(), void (*end());

(missing closing parenthesis after *end).

1
votes

If you are using vim editor, you can easily find missing semicolon by typing:

/[^;]\s*$

...and then jump up/down (with N/n), until problematic line is found.

0
votes

I had similar issue, while error was missing the storage class name in static assignment. E.g.:

.h:
class MyClass {
   static const int something;
}

.cpp:
const int something = 1; // returns error
const int MyClass::something = 1; // OK
0
votes

As Mawg pointed out in a comment, declaring a class member function as extern can cause similar issues.