Home > database >  XCode project's choice of C standard is not being respected
XCode project's choice of C standard is not being respected

Time:07-03

I'm playing around with XCode and C , and I noticed that I change the C standard (i.e. C 98, C 11, GNU17, etc.) by clicking my project in the left sidebar. See screenshot at bottom of this post.

However, when I change to C 98, the C statement auto x = 6; still compiles and runs with no complaints. This is bad because auto requires C 11, so clearly my setting of the standard to C 98 is not in effect. Note that when I say "still compile and run", I mean that I'm clicking the "play" button in XCode.

I imagine several possibilities here:

  • there's some super hidden "save" button that I missed that I'm required to click to actually get the setting to stick
  • the action of "clicking the play button in XCode" does not actually use the new setting but rather uses old settings (and there needs be some kind of "make clean"-like ritual I need to do first in order to get the "play" button to respect new project settings
  • this setting is not working at all and it's a bug in XCode

Anyone know what I'm doing wrong here? I'm using XCode 13.4.1 (latest version as of July 2022) on macOS monterey on 2021 macbook pro 14 inch with M1 pro.

enter image description here

CodePudding user response:

There's another possibility you overlooked:

auto x = 6;

This happens to be a perfectly valid declaration in prehistoric times. auto meant something else entirely, and traces its lineage to C. Nobody was using it, so the keyword was re-purposed in C 11. But, this just happens to be valid code. You might want to try something like:

auto y = "hello world";

and then verify the behavior of your C compiler at various C levels.

  • Related