Like Tree1Likes
  • 1 Post By cas

Compiler Error a storage class can only be specified for objects and functions

This is a discussion on Compiler Error a storage class can only be specified for objects and functions within the C Programming forums, part of the General Programming Boards category; I have some code that I've successfully compiled in a couple of compilers. I am now trying to use CodeBlocks ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    28

    Compiler Error a storage class can only be specified for objects and functions

    I have some code that I've successfully compiled in a couple of compilers. I am now trying to use CodeBlocks with the GCC compiler. I have a header file that declares a number of structures that are used in a DLL. The declarations look like this:

    Code:
    extern struct structure1 {float var1, double var2, int var3};
    The numbers of variables in the structures and their precisions vary. But each one of them is generating the error in the tag line:

    a storage class can only be specified for objects and functions

    Why? How do I correct it? What is different between this compiler and something like VisualStudio where it builds successfully?

    Thank you, in advance, for your help and suggestions.

  2. #2
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    984
    extern is used to inform the compiler that a particular object (variable) exists somewhere else. It can also be used on functions, although there is no syntactic point to do so.

    You have neither an object/variable nor a function here, so extern is not allowed. As far as C is concerned, it has no meaning here. To fix it, remove the extern.

    Why does Visual Studio accept it? Who knows.
    stahta01 likes this.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    28
    Thank you. I removed the extern and, as you said, the error disappears. It is very interesting that Borland, VS and Pelles all pass by that issue.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    is that really your code? or did you accidentally put commas instead of semicolons? in either case it doesn't compile in visual c 2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my error is storage class specified for parameter
    By meli in forum C Programming
    Replies: 5
    Last Post: 03-27-2009, 12:06 PM
  2. error: storage class specified for parameter
    By aim4sky in forum C Programming
    Replies: 20
    Last Post: 03-16-2009, 02:37 AM
  3. Replies: 3
    Last Post: 07-08-2008, 10:01 AM
  4. Replies: 5
    Last Post: 07-17-2006, 03:13 PM
  5. storage class, arrays, functions and good layout
    By disruptivetech in forum C Programming
    Replies: 4
    Last Post: 12-02-2005, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21