length of the internal and external identifiers in Xcode?

The C standard section 5.2.4.1 specifies

  • 63 significant initial characters in an internal identifier or a macro name
  • 31 significant initial characters in an external identifier

is this also a limitation in Xcode when compiling C code?

Replies

The clang compiler is generally C11 compliant:


clang.llvm.org/compatibility.html


so I think you can assume that these limitations are enforced.

Thanks a lot for the info! Yes above limitations should be enforced for Clang based on the doc. But Clang seems already expanded that limit.

I experiented with the external identifier (function name) on Mac with Clang compiler. 60 characters of external identifier builds and works fine. is Clang more similar as GCC? here is what I found for GCC https://gcc.gnu.org/onlinedocs/gcc/Identifiers-implementation.html

The number of significant initial characters in an identifier (C90 6.1.2, C90, C99 and C11 5.2.4.1, C99 and C11 6.4.2).For internal names, all characters are significant. For external names, the number of significant characters are defined by the linker; for almost all targets, all characters are significant.


can I assume for external names, all characters are significant in Clang ?

It's hard to say. It's generally true that clang tried to be compatible with GCC, but it's possible that the two have drifted since the days when both were provided by Xcode.


If you want 60 characters to be signficant, and you're finding that they are (in clang), then I guess you don't have any immediate problem, but you can't assume that this won't change in the future. (I mean, there's no reason why it should, but who knows.)


My suggestion would be to add code at the start of your main() function that tests the result of comparing two globals with names that differ after character 31, and different values. If your desired assumption is ever broken in the future, you'll get a compile error, a link error or a run-time error up front, and you can then take the trouble to deal with the problem.

In a situation where the source code was exceeding the supported ssignificant character limit and it mattered, wouldn't it fail to either compile or link due to conflicting duplicate declarations?


So it shouldn't be necessary to include a comparison statement, just two declarations of different values for names at the required limit.

The comparison would catch the opposite case, of moving to a compiler/linker that didn't make a distinction past 31 characters, if the source code needed that.