First, let's talk a little about your problem. I think that the most likely cause of your system, giving errors in one system over another, is code that is not identical; you can check this with any tool or diff to find any minor changes that appear in your code base. Usually, when Ive seen problems with this type of error, you have something like:
typedef struct Foo* Fooptr;
In the header file, and then:
typedef struct Foo { int bar; } *Fooptr;
in the source file. This means that you can just remove the typedef in the source, and everything should be fine. Just looking for something.
Now, if this is a gcc problem, the second option to solve your problem is to be able to have multiple versions of gcc on the same computer , and then specify the exact version of gcc to run with the -v option. Therefore, it would be nice to give a 4.1.2 shot to your Fedora 18 computer.
Another note: if you use the -v , but do not specify the gcc version to run, you will get (at the output of stderr) the commands executed to start the compilation steps. It can be useful to see what happens and if there are any significant differences between what happens on each machine.
Ok, now for your questions. Yes, there are flags to compile on "version X" gcc : First, there is __VERSION__ Predefined macro , this will return you const char * version numbers. This can be quite useful, but as stated in the gcc documentation:
You should not rely on its contents having any particular form, but you can assume that it contains at least the issue number
Despite this, Ive usually only seen one form of output from this, something like "4.6.3" if my gcc version is 4.6.3-1ubuntu5 .
Now, if you know (or suspect) that any of your code will cause errors for a specific version of gcc , you can use the predefined macros __GNUC__ , __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ to protect "yourself:
Heres a short snip - it shows at the highest level how to use it:
#if __GNC__ == 3 printf("Hello version 3.xx\n"); #elif __GNC__ == 4 printf("Hello version 4.xx\n"); #endif
So, in the above system, where version 4.6.3 you see the message "Hello version 4.xx". Then you can get a more advanced level and check out fakes as well:
#if __GNUC__ > 3 || \ (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \ (__GNUC_MINOR__ == 2 && \ __GNUC_PATCHLEVEL__ > 0)) printf("I'm a gcc greater than 3.2.0\n");
Or a cleaner version using your own macro:
#define GCC_VERSION (__GNUC__ * 10000 \ + __GNUC_MINOR__ * 100 \ + __GNUC_PATCHLEVEL__) #if GCC_VERSION > 30200 printf("I'm a gcc greater than 3.2.0\n"); #endif
To solve the question of whether different versions of gcc create different errors, you are right that more happens in each version of gcc , and sometimes everything changes, so you will see the differences between different versions of the compiler. It is best to check the release notes for each version between the two of you. (from 4.1 to 4.7).
I'm not sure what your target architecture is, so make sure you check these specific sections in each of the documents. But I think that you really want to take a look at "Build system improvements" and "Incompatible changes to the build system" , they also contain a section specific to C code, which can be convenient for viewing.