5 Replies
      Latest reply: Jan 13, 2018 6:07 PM by QuinceyMorris RSS
      wanderyw2003 Level 1 Level 1 (0 points)

        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?

        • Re: length of the internal and external identifiers in Xcode?
          QuinceyMorris Level 7 Level 7 (4,735 points)

          The clang compiler is generally C11 compliant:

           

               clang.llvm.org/compatibility.html

           

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

            • Re: length of the internal and external identifiers in Xcode?
              wanderyw2003 Level 1 Level 1 (0 points)

              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 ?

                • Re: length of the internal and external identifiers in Xcode?
                  QuinceyMorris Level 7 Level 7 (4,735 points)

                  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.