« Phil Smoot on Megaservices | Main | Developer programs: The difference between Apple and Sun »

January 16, 2006




I found an other cause on https://rt.cpan.org/Public/Bug/Display.html?id=12925

"microsoft C compiler wants all variables declared at top of function", which is what is being done in the second example.
That worked perfect for me.

Martin v. Löwis

It's no surprise that Microsoft's compiler wants the variables at the beginnig of the function: Standard C wants them there.

Atleast, this is what C89 defines. C99 allows variable declarations also in the middle of a function.


I don't think is necessarily at the beginning of the function, I think the variables have to be at the beginning of the scope you are in, like this

int function ( )
int x = 1;
int y = 0;
if( x )
int z = 0; //this is ok

Shane Tuohy

The problem is you are using a C file. This means the compiler implements strict C rules. If you change your source file to a cpp type file, you will use the C++ compiler which is myuch more flexible


I was compiling a simple C program and came across this post (when the above described error came up for me) and I agree with @Johann and @Shane Tuohy both are true; just tested them :)

The comments to this entry are closed.

My Photo

Become a Fan

My Other Accounts

Facebook Google Plus Skype Twitter