Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode GCC-4.0 vs 4.2

I have just changed a compiler option from 4.0 to 4.2.

Now I get an error:

jump to case label crosses initialization of 'const char* selectorName'

It works fine in 4.0

Any ideas?

like image 937
John Smith Avatar asked May 22 '10 21:05

John Smith


People also ask

Does Xcode use GCC?

Xcode 4 exploits this modular approach to provide features such as improved syntax highlighting and to suggest fixes to common coding errors. As of writing GCC remains the default compiler for Xcode 3 but with the release of Xcode 4 the default compiler for new projects has changed to LLVM-GCC.

Is GCC good for C++?

The GNU compiler collection, GCC, is one of the most famous open-source tools in existence. It is a tool that can be used to compile multiple languages and not just C or C++. The current version of GCC, GCC 11, has full support for C++17 core language features as well as C++17 library features.

Does Xcode use LLVM?

In Xcode, the LLVM compiler uses the Clang front end (a C-based languages project on LLVM.org) to parse source code and turn it into an interim format. Then the LLVM code generation layer (back end) turns that interim format into final machine code.


2 Answers

Just a guess - you declare variable (probably const char*) inside 1 of your switch-case statements - you should wrap that case in {} to fix that.

// error
case 1:
   const char* a = ... 
   break; 

// OK
case 1:{
   const char* a = ... 
}
   break; 
like image 196
Vladimir Avatar answered Sep 25 '22 23:09

Vladimir


You probably declare a variable inside a case without wrapping it all in a brace:

case foo:
    const char* selectorName;
    // ...
    break;

Should be:

case foo: {
    const char* selectorName;
    // ...
    break;
}
like image 39
Mike Weller Avatar answered Sep 26 '22 23:09

Mike Weller