tknickman
tknickman

Reputation: 4641

Use gcc in Xcode 4.6

For my CPS classes this semester we are transitioning from C++ down to C. For my C++ I grew attached to xCode and it's quick and easy debugger. However, for C, xCode is letting me do a lot of stuff C++ that I shouldn't be allowed to do in C.

For example, I can initialize and declare a loop variable from within a loop, which is not allowed in C.

C:

int i
for(i = 0; i < 100; i++)
{
     printf("This is a number: %i", i);
}

But IS allowed in C++ C++:

for(int i = 0; i < 100; i++)
{
     printf("This is a number: %i", i);
}

All my work has to be compiled on a lab machine (running linux and compiling with gcc) in order for it to count, so I am looking for a way to continue using xCode to run my programs with gcc (or at least something that won't let me do C++ stuff). It seems xCode has dropped gcc support. Is there anyway I can continue to use xCode but have it compile in an "old-school" school way so it will catch things like this?

For now I have been using sublime2 and just compiling in the terminal. Which is fine for now, but when it comes to debugging I have developed a hatred for gdb after using xCode for so long.

Upvotes: 0

Views: 415

Answers (1)

Kurt Revis
Kurt Revis

Reputation: 27994

You can tell clang what dialect of C to use using the -std argument to the compiler. It sounds like you may want -std=c89 or -std=gnu89.

In Xcode, in the Build Settings for your project or target, set "C Language Dialect" to whatever you want.

I wouldn't count on this catching everything, but it should get you closer.

Upvotes: 1

Related Questions