Run the test case on a x86_64 bit machine to see how gcc 4.1.2 mangles results in under Linux We have tested the test case using 3.2.3 Compiler on RHEL 3 on both 32 as well as 64 bit OS it works well. Compile the test case provided with the following steps $gcc -g -I. -Wall -m64 -c bar.c $g++ -g -I. -Wall -m64 -o foo foo.c bar.o Actual results: once you run the program foo you will see the following result foo: i is 3. bar: i is 3221205968. Expected results: foo: i is 3. bar: i is 3. Additional info: Test Case follows ----- bar.h ----- typedef struct { unsigned b1:16; unsigned b2:16; } foo; #ifdef __cplusplus extern "C" { #endif foo bar(unsigned); #ifdef __cplusplus } #endif ----- bar.c ----- #include <stdio.h> #include <bar.h> foo bar(unsigned i) { foo myfoo; myfoo.b1=myfoo.b2=0; printf("bar: i is %u.\n",i); return(myfoo); } ----- foo.c ----- #include <stdio.h> #include <bar.h> int main(void) { foo myfoo; unsigned i = 3; printf("foo: i is %u.\n",i); myfoo = bar(i); return 0; }
Confirmed. Here's a slightly simplified testcase: -----------bar.h------------ typedef struct { unsigned : 16; unsigned : 16; } foo; -----------bar.c------------ #include <stdio.h> #include <bar.h> foo bar(unsigned i) { printf("bar: i is %u.\n",i); foo myfoo; return myfoo; } -------------foo.cc------------ #include <stdio.h> #include <bar.h> extern "C" foo bar(unsigned int); int main(void) { foo myfoo; unsigned i = 3; printf("foo: i is %u.\n",i); myfoo = bar(i); return 0; } ------------------- tmp/g> gcc -I. -c bar.c tmp/g> g++ -I. -o foo foo.c bar.o tmp/g> ./foo foo: i is 3. bar: i is 1289971520. Something appears to go wrong when calling the extern "C" function... This is a wrong-code regression on valid code. W.
Closing 4.1 branch.