gcc peculiarities

Vivek Srivastava u2000159@cs.unipune.ernet.in
Tue Feb 26 08:23:00 GMT 2002


Hi,

There are a couple of things which I need help understanding: 

1. 	
	main()
	{
	   int a[3];
	}

For the above C code gcc allocates 24 bytes on the stack while there should 
be only 12. Everything's ok till the size is 1 or 2. For a size of 10, it 
allocates 56 bytes. Can anyone explain what those extra bytes are for.


2. This one also realtes to arrays. The ANSI C language definition 
disallows variable length array declarations. So something like 
	int a [x]
is incorrect. However, not only gcc compiles it properly, it generates all 
sorts of assembly for a simple 2 liner like
	main()
	{
	   int x;
           int a [x];
	}

Moreover, it also works properly!! Not until I compiled it with the 
-pedantic option was a warning about this issued. (No, not even -ansi 
worked.) The same thing was rejected by Microsoft and Borland compilers.
What's happening in there?!

Thanks.

--
Vivek Srivastava
MCA II
University of Pune




More information about the Gcc-help mailing list