This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: cc and gcc compilers


 The information transmitted is for the use of the intended recipient only and may contain confidential and/or legally privileged material. Any review, re-transmission, disclosure dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited and may result in severe penalties.  If you have received this e-mail in error please notify the Privacy Hotline of the Australian Taxation Office, telephone 13 28 69 and delete all copies of this transmission together with any attachments. 

Many thanks for the replies. My apology for the Disclaimer. Please ignore
it. The disclaimer is generated atomatically by my organisation system.

Colin's reply described exactly what happens to our system. Also when
searching on internet I found that Zgene got the same problem and Dan
suggested that with a new gcc version (3.x.x) may accept mixed declarations
and code (attached). We hope that it's the case.

Our current version of gcc is 2.9-aix51-020209. Is it old? Is there a newer
version of gcc for AIX which can accept mixed declarations and code?

Conversion our 500 c programs (moving declaration to top of function) is our
last option if we cannot find any options in gcc which accept mixed
declarations and code.

If we have no other choices and we have to convert them. Any automate
conversion softwares we can use to convert them (instead of manually
converting them - we might introduce more problems by mistakes when manually
convert them)?

Please help. Many thanks for your time.

KhaiDinh Nguyen

From: Dan Pop (
Subject: Re: What a stupid gcc!
View: Complete Thread (14 articles)
Original Format
Newsgroups: comp.lang.c
Date: 2002-06-20 09:12:10 PST

In <aerd8p$3s2$> writes:

>Look at this code:
>1. #include<stdio.h>
>2. 3. main()
>4. { const int *pc;
>5.  int i = 10;
>7.  pc = &i;
>8.  printf("%d\n", *pc);
>10.  int c = 2;
>11.  pc = &c;
>12.  printf("%d\n", *pc);
>13. }
>If I compile this code with gcc, I get:
>myprompt> gcc PtrTest.c
>PtrTest.c: In function `main':
>PtrTest.c:9: parse error before `int'
>PtrTest.c:10: `c' undeclared (first use in this function)
>PtrTest.c:10: (Each undeclared identifier is reported only once
>PtrTest.c:10: for each function it appears in.)
>Whereas g++ compiles it nicely.  Look:
>myprompt> g++ PtrTest.c
>However, if I move Line 10 to Line 6, gcc also compiles it nicely.
>So, does g want us to declare all variables at the head of a block?
>What a stupid gcc!

What a stupid poster!

The code is invalid as both a C89 program (the misplaced declaration) and a
C99 program (the implicit int for the return value type is no longer

Recent versions of gcc will actually silently accept your garbage, if
invoked in the default GNU C mode, but will diagnose it in either C89 and
C99 mode:

    fangorn:~/tmp 1085> gcc test.c
    fangorn:~/tmp 1086> gcc -ansi -pedantic test.c
    test.c: In function `main':
    test.c:10: warning: ISO C89 forbids mixed declarations and code
    fangorn:~/tmp 1087> gcc -std=c99 test.c
    test.c:4: warning: type defaults to `int' in declaration of `main'
    fangorn:~/tmp 1088> gcc -v
    Reading specs from 
    Configured with: ./configure --prefix=/products/gnu/gcc3/v3.0
    Thread model: single
    gcc version 3.0.3

Dan Pop
DESY Zeuthen, RZ group

-----Original Message-----
From: Colin Douglas Howell [] 
Sent: Thursday, 23 October 2003 06:06
To: Jim Wilson
Cc: Nguyen, KhaiDinh;
Subject: Re: cc and gcc compilers

Jim Wilson wrote:
> Nguyen, KhaiDinh wrote:
>> We are migating many C programs from (old) NCR Unix system to AIX. 
>> These C programs are non-ansi standard and compiled by using NCR unix 
>> cc compiler.
> See for info on how to report bugs.
> This report is very confusing.  In one place you imply that the C code
> is very old, and thus pre-dates ANSI C (aka ISO C90).  In another place, 
> you imply that the code won't compile because it uses an ISO C99 
> feature, and thus post dates ANSI C (aka ISO C90).  Which is it?  A 
> testcase would be very helpful to eliminate the confusion.  If we don't 
> know what exact problem you are seeing, then we may not be able to help.


I think you're misreading the situation.

Mr. Nguyen said that the system was an old NCR Unix system, not that the
code was pre-ANSI C.  (He said that the code was *non-ANSI*, not pre-ANSI.)
He also said that the code used features like "variable declared after
statements/variable assignments".  It turns out that this is a extension
provided by NCR's proprietary High Performance C/C++ Compiler.  This
compiler defines a language called High C which has a bunch of extensions to
ANSI standard C.  It can also operate in strict ANSI-compatible mode. Or it
can operate in a pre-ANSI compatible mode which also allows limited usage of
ANSI constructs and High C extensions.

I found a manual for this compiler, dated 12/1997, on NCR's web site:

It's a PDF.  Page 305 of the manual describes the mixed declarations and
statements extension; this page is part of Appendix F, which starts on page
294 and describes the extensions provided by High C.

In short, it sounds like Mr. Nguyen's code uses NCR proprietary extensions.
For that code to work on other systems, those extensions must be removed. If
Mr. Nguyen's team is very lucky, the extensions they used might just happen
to fall under the new ISO C99 standard, so compiling in that mode might
work; more likely, they will have to convert the code themselves, possibly
with the help of automated scripts.  The NCR compiler may be able to help in
that conversion; for example, the -Hansi option enforces strict ANSI
compliance, and might be usable to flag usage of extensions; also some
specific compiler features can be controlled with toggles (I don't think
that mixing statements and declarations is one of those).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]