Maximum Function / Variable Name Identifier Length?

Discussion in 'C Programming' started by David T. Ashley, Jan 2, 2007.

  1. 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_sqrt();

    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 microcontrollers.

    Any insight or traceability to standards would be appreciated.

    Dave.
     
    David T. Ashley, Jan 2, 2007
    #1
    1. Advertising

  2. David T. Ashley

    jacob navia Guest

    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_sqrt();
    >
    > 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 microcontrollers.
    >
    > 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.
     
    jacob navia, Jan 2, 2007
    #2
    1. Advertising

  3. 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_sqrt();
    >
    > 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.
     
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=, Jan 2, 2007
    #3
  4. David T. Ashley

    aegis Guest

    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_sqrt();
    > >
    > > 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
     
    aegis, Jan 2, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. harry
    Replies:
    11
    Views:
    971
    Roedy Green
    Feb 1, 2006
  2. Kobu
    Replies:
    7
    Views:
    502
  3. Replies:
    2
    Views:
    1,847
  4. Replies:
    2
    Views:
    950
    Owen Jacobson
    Dec 11, 2007
  5. S_K
    Replies:
    0
    Views:
    693
Loading...

Share This Page