1

Is there any way to compile C code with c89 standard NOT c99 in Xcode (or another way with terminal)?

I've searched in Xcode settings but I didn't find any way to choose compiler or standard.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
White Hat
  • 681
  • 1
  • 6
  • 15
  • Referencing [this question](http://stackoverflow.com/questions/12291202/how-to-add-two-compiler-flags-in-xcode), you could add the compiler flag `-std=c89.` – John M Jun 12 '15 at 03:04
  • Search again. Select your project, then in the right pane, select Build Settings, underneath that select All/Combined, and then in the search box type `C language`. The language dialect options will be there to choose from, and c89 is among them. – WhozCraig Jun 12 '15 at 03:04
  • I've tried this, but it didn't work. for example, I used initialisation in for loop like this: for(int i = 0; i < N; i++){ } and it didn't show any problem - it worked successfully without anything wrong, – White Hat Jun 12 '15 at 03:26
  • It will probably end up being a bug in Apple's clang, because I just tried it from the command line sans-Xcode, just for the hell of it. Even going back to `-ansi`, much less `-std=c89`, loop-var-declarations still pass. Dunno what the problem is, maybe someone already filed a bug with Apple. Bummer. – WhozCraig Jun 12 '15 at 04:04

1 Answers1

4

You should add -pedantic-errors to Other C flags in your project settings, like so:

Solution

Of course, don't forget to set the C language dialect to C89 as well.

This will give you the appropriate compile time errors when you try to compile something that is not valid C89.

Optionally, if you want Xcode to compile your code regardless of incompatibilities, but only give you yellow warnings at the problematic lines, use -pedantic instead of -pedantic-errors.

In a nutshell, these flags make the compiler stick to the language standard more strictly, as opposed to the default behavior, which is to attempt compiling the code any way possible.

I hope this helps :)

Source (even though they mention this in the context of GCC, but the same flags apply for Clang as well)

Community
  • 1
  • 1
notadam
  • 2,754
  • 2
  • 19
  • 35