This is the mail archive of the gcc-bugs@gcc.gnu.org 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]

Re: Different behavior of g++ and gcc (both egcs) compilers


Alex Vinokur <alexander.vinokur@telrad.co.il> writes:
> Hi,
> 
> Here is a simple program.
> Why is the g++ and gcc (both egcs) compilers' behavior different?
> 
>         Thanks in advance,
>         Alex
> 
> 
> 
> //#########################################################
> //------------------- C++ code : BEGIN -------------------
> // main.C
> 
> int n = 0;
> void foo (char a [n])
> {                       // Line#3
> }
> 
> int main()
> {
>         return 0;
> }
> 
> 
> //------------------- C++ code : END ----------------------
> 
> //#########################################################
> //------------------- Compilation Results : BEGIN ---------
> 
> %g++ main.c
> main.c:3: variable-size type declared outside of any function
> 
> %gcc main.c     // OK
> 

When you compile .c file with gcc driver, it's compiled as C; when
you compile .c file with g++ driver, it's compiled as C++. Now
compile with -ansi -pedantic (to disable GCC extensions), look at
the messages from gcc/g++ and then see if it makes sense to you.

It's not a bug in the compiler.

Regards,
Mumit


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