• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: crosses initialization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: crosses initialization


  • Subject: Re: crosses initialization
  • From: Eric Albert <email@hidden>
  • Date: Sun, 21 May 2006 10:05:44 -0700

On May 21, 2006, at 5:54 AM, Jonathan Taylor wrote:

I see from the archives this sort of question has been asked before, but none of the answers seem to address my current problem.

I have a whole load of code which involves code similar to the following test case:

long bar(void) { return 2; }

void foo(void)
{
goto ExitLabel;
long temp = 1;
long temp2 = bar();
long temp3 = 3;
long temp4;
temp4 = 4;
ExitLabel:
    return;
}

This always used to compile fine, but after I had to reinstall the OS (and thus the development tools as well), this code has stopped compiling. I get errors saying:

/Volumes/Development/temp/main.cpp: In function 'void foo()':
/Volumes/Development/temp/main.cpp:11: error: jump to label 'ExitLabel'
/Volumes/Development/temp/main.cpp:5: error:   from here
/Volumes/Development/temp/main.cpp:8: error:   crosses initialization of 'long int temp3'
/Volumes/Development/temp/main.cpp:6: error:   crosses initialization of 'long int temp'
/Volumes/Development/temp/main.cpp:6: warning: unused variable 'temp'
/Volumes/Development/temp/main.cpp:7: warning: unused variable 'temp2'
/Volumes/Development/temp/main.cpp:8: warning: unused variable 'temp3'

Notice that the compiler is NOT objecting to the initialization of temp2 or temp4, CW compiles the code fine, and GCC 4 certainly always used to compile it ok until today(!). My understanding is that (at least under C99) this is perfectly valid code as long as the variables being initialized are basic types rather than classes requiring constructors.

You're right...this is OK in C99.  However, see below....

The command line is:
CompileC build/temp.build/Debug/temp.build/Objects-normal/ppc/main.o /Volumes/Development/temp/main.cpp normal ppc c++ com.apple.compilers.gcc.4_0
    cd /Volumes/Development/temp
    /usr/bin/gcc-4.0 -x c++ -arch ppc -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -g -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -mtune=G5 -fvisibility=hidden -fvisibility-inlines-hidden -mfix-and-continue -Wno-invalid-offsetof -mmacosx-version-min=10.4 -I/Volumes/Development/temp/build/temp.build/Debug/temp.build/temp.hmap -F/Volumes/Development/temp/build/Debug -I/Volumes/Development/temp/build/Debug/include -I/Volumes/Development/temp/build/temp.build/Debug/temp.build/DerivedSources -isysroot /Developer/SDKs/MacOSX10.4u.sdk -c /Volumes/Development/temp/main.cpp -o /Volumes/Development/temp/build/temp.build/Debug/temp.build/Objects-normal/ppc/main.o

... and indeed "cc main.cpp" reports the same errors.

This is a C++ file.  Unfortunately, C99 doesn't apply to C++ -- from a standards standpoint they're two different languages.  I think they C++ folks are working on a revision which among other things will integrate C99 into the C++ standard, but they haven't finalized it yet so GCC doesn't support it today.  I don't know if this is valid C++; it might be, in which case this is a compiler bug, but it might not be.  It's certainly a little odd to get an error about jumping past the initialization of an unused variable.

You can work around this by renaming main.cpp to main.c or otherwise compiling it as C code, but I'm not sure if there's a way to make this work for C++ without changing the code.

-Eric

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: crosses initialization
      • From: Jonathan Taylor <email@hidden>
References: 
 >crosses initialization (From: Jonathan Taylor <email@hidden>)

  • Prev by Date: Re: /Developer/Private/jam failed with exit code 1
  • Next by Date: Re: crosses initialization
  • Previous by thread: crosses initialization
  • Next by thread: Re: crosses initialization
  • Index(es):
    • Date
    • Thread