C enumeration of various compilers

I am creating an application that needs to be compiled on both Windows and Linux. The application is written in C, almost everything works, except the MinGW compiler refuses to do so

typedef struct somestruct{
   ...snip...
   enum {NODE, REAL} type;
};

somestruct* something;
switch (something->type){
 case NODE:
   ...stuff...;
   break;
 case REAL:
   ...otherstuff...;
   break;
}

      

It says NODE and REAL are undefined, But if I put scope permission

case somestruct::NODE

      

This compiles with MinGW 3.4.1, but will not compile with gcc 4.1.2 on linux. Is this just a compiler problem that needs to be solved with preprocessors or is there some other explanation?

+1


a source to share


2 answers


If you get rid of the nesting, it should work portable:

typedef enum somestruct_type {
    somestruct_type_NODE, somestruct_type_REAL
} somestruct_type;
typedef struct somestruct {
   ...snip...
   somestruct_type type;
} somestruct;

      



I have seen that code very similar to this is ported to a large number of C and C ++ compilers.

(I'm not saying this is the only way to do it, I'm just saying that it works).

+3


a source


The application is written in "C", but the compiler requires you to execute somestruct::NODE

, which is valid "C ++" but not valid "C".

Conclusion: You are compiling this code with MinGW in C ++ mode, but with all other compilers in C mode.



Likely cause: MinGW cannot handle the foo.C

and tags foo.C

, and your files are named with a capital suffix C (which is what C ++ on UNIX means).

Solution: Add a flag -xc

to MinGW to force compile C compilation.

+6


a source







All Articles