Re: c compiler: Problems with constants

Michal Moskal <[email protected]>
Newsgroups gmane.comp.gnu.dotgnu.developer
Message-ID <[email protected]>
On Tue, Mar 23, 2004 at 07:38:10PM +1000, Rhys Weatherley wrote:
> > main ()
> > {
> >         int i;
> >         {
> >                 /* do nothing*/
> >         }
> >         int j;
> > }
> >
> > I guess this is because cscc assumes that something apart from variable
> > declarations happens inside the subblock - which excludes futher variable
> > declarations i.e. the declaration of j - at the parsing level.  Presumably
> > gcc leaves this check until later when it can see that the subblock
> > contains nothing that is not a variable declaration inside.
> 
> Traditional ANSI C only allows declarations at the head of a block.  C++ 
> allows them anywhere in a block.  The latest version of gcc follows the C++ 
> model.  Until recently, such code was considered invalid in C.

I believe this is C99 model, not C++ one.

> I personally think that it *should* be invalid because it causes sloppy coders 
> to write C code that won't compile on most of the world's existing C 
> compilers, harming code portability in the process.  This is why I do most of 
> my development with gcc 2.x, not gcc 3.x - the resulting C code is more 
> portable.

It warns about it, with -pedantic. IMHO it should treat it as error in
C89 mode, but ...

<flame>Another thing to think about is that C99 is ergh.. 5 years old,
so maybe there is little point in supporting ancient compilers :-)</flame>

-- 
: Michal Moskal :: http://www.kernel.pl/~malekith :: GCS !tv h e>+++ b++
: When in doubt, use brute force. -- Ken Thompson :: UL++++$ C++ E--- a?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.