By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

Maximum Function / Variable Name Identifier Length?

P: n/a
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.
Jan 2 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
Jan 2 '07 #2

P: n/a
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.

Jan 2 '07 #3

P: n/a

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

Jan 2 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.