• 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: Jonathan Taylor <email@hidden>
  • Date: Sun, 21 May 2006 18:33:14 +0100

Thanks for your explanation Eric. It may be that I will have to rewrite all the code. However, let me just emphasize again that I have had vast amounts of code like this successfully compiling under Xcode for months, if not years, until I reinstalled yesterday. I would love to know what has somehow changed to break it...

(plus, if this really is standards-based behaviour it seems immensely odd to forbid "long temp = 1" but not "long temp2 = bar()" where bar() returns a long...)

Following you're C/C++ comment, I've confirmed that the code below does indeed compile successfully in a C file. Unfortunately the existing code I've suddenly started having problems with is very much C++.

On 21 May 2006, at 18:05, Eric Albert wrote:

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;
}
You're right...this is OK in C99.  However, see below....

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: Paul Russell <email@hidden>
References: 
 >crosses initialization (From: Jonathan Taylor <email@hidden>)
 >Re: crosses initialization (From: Eric Albert <email@hidden>)

  • Prev by Date: Re: crosses initialization
  • Next by Date: Running a newly created project
  • Previous by thread: Re: crosses initialization
  • Next by thread: Re: crosses initialization
  • Index(es):
    • Date
    • Thread