Maximum Function / Variable Name Identifier Length?

  • Thread starter David T. Ashley
  • Start date
D

David T. Ashley

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

jacob navia

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

Guest

David said:
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.
 
A

aegis

Harald said:
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."
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top