Max identifier length

前端 未结 4 646
野趣味
野趣味 2020-12-08 22:09

Where can I find what is the maximum identifier length in C?

In which header file is that limit specified?

4条回答
  •  心在旅途
    2020-12-08 22:45

    In short, no header file exists to tell you that, that is part of a ANSI/ISO C Standard specifications which defines the layout of the syntax and environment mechanism for the C language itself. In pre C89 standards, the maximum identifier length was 6, due to the small memory footprints and environment on such systems such as mainframes and *nix systems.

    Today, the latest standard is C99 standards which dictate that the maximum length for an identifier is to be 32, the reason is quite simple and logical...the compiler works by parsing the input stream which would be passed as a command line argument, makefile, or a solution (for Microsoft Visual Studio environments), the parser is rigid and fixed and hence the imposed restrictions on the length of the identifier so that the parser can look ahead and see if there's any more characters. It's down to that reason for it.

    Another reason is that most C++ compilers use name mangling on the identifiers which, as Jonathan Leffler pointed out, could confuse the compiler and also the linkage of the code.

提交回复
热议问题