Maximum Function / Variable Name Identifier Length?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David T. Ashley

    Maximum Function / Variable Name Identifier Length?

    I have this ugly habit of prefixing all function and variable names with
    some identifying information about the owning module and perhaps also the
    subcategory of function, i.e.

    CGIX_ARBINT_sqr t();

    In a few cases, these names have become rather long.

    For both functions and variables, how long can I safely go without running
    into the risk of two different names being treated the same by the compiler
    or the linker? What standards apply?

    The three compilers I use are:

    a)gcc on x86/Linux.

    b)MS VC++.

    c)Cosmic's suite for microcontroller s.

    Any insight or traceability to standards would be appreciated.

    Dave.


  • jacob navia

    #2
    Re: Maximum Function / Variable Name Identifier Length?

    David T. Ashley a écrit :
    I have this ugly habit of prefixing all function and variable names with
    some identifying information about the owning module and perhaps also the
    subcategory of function, i.e.
    >
    CGIX_ARBINT_sqr t();
    >
    In a few cases, these names have become rather long.
    >
    For both functions and variables, how long can I safely go without running
    into the risk of two different names being treated the same by the compiler
    or the linker? What standards apply?
    >
    The three compilers I use are:
    >
    a)gcc on x86/Linux.
    >
    b)MS VC++.
    >
    c)Cosmic's suite for microcontroller s.
    >
    Any insight or traceability to standards would be appreciated.
    >
    Dave.
    >
    >
    The C standard guarantees in 5.2.4.1: Translation limits

    <quote>
    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
    < end quote>

    This are minimum requirements. gcc and msvc have
    probably much more, but be careful with compilers for embedded systems.

    Comment

    • =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=

      #3
      Re: Maximum Function / Variable Name Identifier Length?

      David T. Ashley wrote:
      I have this ugly habit of prefixing all function and variable names with
      some identifying information about the owning module and perhaps also the
      subcategory of function, i.e.
      >
      CGIX_ARBINT_sqr t();
      >
      In a few cases, these names have become rather long.
      >
      For both functions and variables, how long can I safely go without running
      into the risk of two different names being treated the same by the compiler
      or the linker? What standards apply?
      For C99, you can assume 31 significant characters for external names,
      and 63 significant characters for internal and macro names. For C90, I
      believe you can only assume 6 significant characters for external
      names, and for internal and macro names I don't know. However, those
      are the minimum limits. The exact limits are implementation-defined, so
      you should be able to find those documented by your implementations .

      Comment

      • aegis

        #4
        Re: Maximum Function / Variable Name Identifier Length?


        Harald van Dijk wrote:
        David T. Ashley wrote:
        I have this ugly habit of prefixing all function and variable names with
        some identifying information about the owning module and perhaps also the
        subcategory of function, i.e.

        CGIX_ARBINT_sqr t();

        In a few cases, these names have become rather long.

        For both functions and variables, how long can I safely go without running
        into the risk of two different names being treated the same by the compiler
        or the linker? What standards apply?
        >
        For C99, you can assume 31 significant characters for external names,
        and 63 significant characters for internal and macro names. For C90, I
        believe you can only assume 6 significant characters for external
        names, and for internal and macro names I don't know. However, those
        are the minimum limits. The exact limits are implementation-defined, so
        you should be able to find those documented by your implementations .
        c89 Says:

        "The implementation shall treat at least the first 31 characters of
        an internal name (a macro name or an identifier that does not have
        external linkage) as significant. Corresponding lower-case and
        upper-case letters are different. The implementation may further
        restrict the significance of an external name (an identifier that has
        external linkage) to six characters and may ignore distinctions of
        alphabetical case for such names./10/ These limitations on identifiers
        are all implementation-defined."

        --
        aegis

        Comment

        Working...