Saturday, October 1, 2016

C variable name length limit

Original C dictates that

  • The first 31 chars of an internal (i.e. not an external variable) variable name is significant.
  • The first 6 characters of an function name or external variable is significant
For C99 this is 63 and 61 chars
For C++ (GCC 1024, MS 2048)

another posting says:

  • Microsoft C++: 2048 characters
  • Intel C++: 2048 characters
  • g++: No limit, as answered in this question: is there a length limit on g++ variable names?

another posting says:

    Annex B of the C++ Standard says that an implementation should support identifiers at least 1024 characters long, but this is not mandatory.

The C standard, section says:

  • 63 significant initial characters in an internal identifier or a macro name (each universal character name or extended source character is considered a single character)
  • 31 significant initial characters in an external identifier (each universal character name specifying a short identifier of 0000FFFF or less is considered 6 characters, each universal character name specifying a short identifier of 00010000 or more is considered 10 characters, and each extended source character is considered the same number of characters as the corresponding universal character name, if any)
It also contains a footnote:
Implementations should avoid imposing fixed translation limits whenever possible. So you should check your documentation to see if your compiler supports a greater number of significant characters in identifiers.

  1. Rules For Constructing Variable Name

    Characters Allowed :

    • Underscore(_)
    • Capital Letters ( A – Z )
    • Small Letters ( a – z )
    • Digits ( 0 – 9 )
    • Blanks & Commas are not allowed
    • No Special Symbols other than underscore(_) are allowed
    • First Character should be alphabet or Underscore
    • Variable name Should not be Reserved Word

  2. Naming Rules for Variables

    • Variable names in Visual C++ can range from 1 to 255 characters. To make variable names portable to other environments stay within a 1 to 31 character range.
    • All variable names must begin with a letter of the alphabet or an underscore( _ ). For beginning programmers, it may be easier to begin all variable names with a letter of the alphabet.
    • After the first initial letter, variable names can also contain letters and numbers. No spaces or special characters, however, are allowed.
    • Uppercase characters are distinct from lowercase characters. Using all uppercase letters is used primarily to identify constant variables.
    • You cannot use a C++ keyword (reserved word) as a variable name.

  3. C/C++ – Variable and method name length limit
  4. What is max length for an C/C++ identifier on common (build) systems?
  5. Identifiers (C++)
  6. Max identifier length
  7. Variable Names

    In C the length of a variable name is unlimited (although the first 31 characters must be unique). So variable names like these:
    disk_name total_count last_entry
    are legal.

  8. File Basics, Comments, and Program Headings
  9. Style and Program Organization
  10. Statement Formatting
  11. Statement Details
  12. Preprocessor
  13. Directory Organization and Makefile Style

No comments:

Post a Comment