Connecting Tech Pros Worldwide Forums | Help | Site Map

Variable Length

lak
Guest
 
Posts: n/a
#1: Nov 3 '07
I want to know what is the variable length in c.
I K&R they stated that atleast 31 character.
But I give 1 lakhs length to a variable, but my compiler doesn't say
any error.
It accepts it.Then what is the maximum length to a variable name.?


James Kuyper
Guest
 
Posts: n/a
#2: Nov 3 '07

re: Variable Length


lak wrote:
Quote:
I want to know what is the variable length in c.
I K&R they stated that atleast 31 character.
But I give 1 lakhs length to a variable, but my compiler doesn't say
any error.
It accepts it.Then what is the maximum length to a variable name.?
>
The limit is on identifiers, not just variable names; function names,
for instance, are also identifiers.

The 31 character limit is only on external identifiers. Internal
identifiers have a limit of 63 (5.2.4p1).

That limit is a minimum, not a maximum. "There is no specific limit on
the maximum length of an identifier." (6.4.1p2).

The minimum limit is a requirement on the implementor, not on the
developer. It means that if two external identifiers differ in their
first 31 characters, an implementation is required to recognize them as
being different. If the first difference occurs after the 31st
character, an implementation is allowed, but not required, to treat the
two identifiers as being the same, which usually causes problems
somewhere during compilation, unless it was only a typo, in which case
it can cause confusion in readers of the code.

A good compiler should warn you if you have two external identifiers
that differ only after the 31st character. A picky compiler might warn
you about even using identifiers longer than 31 characters. That's a
useful warning, because human readers can be easily misled into thinking
the whole identifier is meaningful, rather than just the first 31
characters.
santosh
Guest
 
Posts: n/a
#3: Nov 3 '07

re: Variable Length


lak wrote:
Quote:
I want to know what is the variable length in c.
I K&R they stated that atleast 31 character.
But I give 1 lakhs length to a variable, but my compiler doesn't say
any error.
It accepts it.Then what is the maximum length to a variable name.?
The minimum limits are given in the C Standard. Implementations may
relax these restrictions further as appropriate.

PS. An identifier of hundred thousand characters is nothing short of
mad. Was there a reason for your pointless exercise?

Tor Rustad
Guest
 
Posts: n/a
#4: Nov 3 '07

re: Variable Length


James Kuyper wrote:

[...]
Quote:
The limit is on identifiers, not just variable names; function names,
for instance, are also identifiers.
>
The 31 character limit is only on external identifiers. Internal
identifiers have a limit of 63 (5.2.4p1).
I'm rather sure that limit was far less before C99.

I don't have access to C89 std. here, but if memory serves me right,
minimum of 8 initial characters was significant (external identifiers).


--
Tor <torust [at] online [dot] no>

Kenny McCormack
Guest
 
Posts: n/a
#5: Nov 3 '07

re: Variable Length


In article <fghu1k$f9t$2@aioe.org>, santosh <santosh.k83@gmail.comwrote:
Quote:
>lak wrote:
>
Quote:
>I want to know what is the variable length in c.
>I K&R they stated that atleast 31 character.
>But I give 1 lakhs length to a variable, but my compiler doesn't say
>any error.
>It accepts it.Then what is the maximum length to a variable name.?
>
>The minimum limits are given in the C Standard. Implementations may
>relax these restrictions further as appropriate.
>
>PS. An identifier of hundred thousand characters is nothing short of
>mad. Was there a reason for your pointless exercise?
You might want to Google the words "test" and "experiment".

You do get credit though for looking up and tranlating for us the Indian
numbering system.

santosh
Guest
 
Posts: n/a
#6: Nov 3 '07

re: Variable Length


Tor Rustad wrote:
Quote:
James Kuyper wrote:
>
[...]
>
Quote:
>The limit is on identifiers, not just variable names; function names,
>for instance, are also identifiers.
>>
>The 31 character limit is only on external identifiers. Internal
>identifiers have a limit of 63 (5.2.4p1).
>
I'm rather sure that limit was far less before C99.
>
I don't have access to C89 std. here, but if memory serves me right,
minimum of 8 initial characters was significant (external
identifiers).
I think it was six initial characters and case insensitive too. A
concession to the limitations of some of the linkers back then.

James Kuyper
Guest
 
Posts: n/a
#7: Nov 3 '07

re: Variable Length


Tor Rustad wrote:
Quote:
James Kuyper wrote:
>
[...]
>
Quote:
>The limit is on identifiers, not just variable names; function names,
>for instance, are also identifiers.
>>
>The 31 character limit is only on external identifiers. Internal
>identifiers have a limit of 63 (5.2.4p1).
>
I'm rather sure that limit was far less before C99.
>
I don't have access to C89 std. here, but if memory serves me right,
minimum of 8 initial characters was significant (external identifiers).
That sounds about right; the limit was expanded in C99 because it was
felt to be no longer necessary to accommodate old linkers that didn't
support names longer than 8 characters.

However, I can't verify the precise number under the old standard. When
I wanted a copy of the C90 standard, it was way too expensive. By the
time it dropped down to a reasonable price, it was no longer the current
standard, and I was therefore no longer interested in it.
Malcolm McLean
Guest
 
Posts: n/a
#8: Nov 3 '07

re: Variable Length



"lak" <lakindia89@gmail.comwrote in message
Quote:
>I want to know what is the variable length in c.
I K&R they stated that atleast 31 character.
But I give 1 lakhs length to a variable, but my compiler doesn't say
any error.
It accepts it.Then what is the maximum length to a variable name.?
>
Typically a compiler will accept variables of any length until extreme
limits such as the amount of memory in the computer are hit.
However it is not obliged to accept more than 31 characters. That is a
concession to simple compilers. Nowadays the speed gain to be had from using
a fixed-size field is much less significant.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


Keith Thompson
Guest
 
Posts: n/a
#9: Nov 3 '07

re: Variable Length


lak <lakindia89@gmail.comwrites:
Quote:
I want to know what is the variable length in c.
I K&R they stated that atleast 31 character.
But I give 1 lakhs length to a variable, but my compiler doesn't say
any error.
It accepts it.Then what is the maximum length to a variable name.?
The C90 standard requires compilers to support a minumum of 31
significant initial characters in an internal identifier or macro
name, 6 in an external identifier. I recall that external identifiers
that differ only in case ("foo" vs. "Foo") are not required to be
treated as distinct, but in a quick look at the C90 standard I didn't
find a reference to that.

C99 increases this to 63 characters for internal identifiers, 31 for
external identifiers. I believe that identifiers differing only in
case are required to be treated as distinct, but again, I didn't find
a reference to that in the standard (I'm sure it's there, I just
didn't take the time to find it).

However, compilers aren't required to impose these restrictions; these
are just the minimum they're required to support. A compiler that
allows identifiers of any arbitrary length meets the standard's
requirements. Furthermore, even if the compiler imposes limits, the
limit is on the initial significant characters, not on the full length
of the identifier. For example, a compiler might allow both
this_is_a_very_very_long_identifier
and
this_is_a_very_very_long_identical identifier
as external identifiers, but treat them as the same (because they
match in the first 31 characters). A compiler may (but need not)
impose a limit of at least 509 characters (C90) or 4095 (C99)
characters in a logical source line, and an identifier can't span more
than one source line -- but again, a compiler isn't required to impose
any limit at all.

Incidentally, most people here aren't likely to know that "lakh" means
one hundred thousand; the word is rarely used outside India.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Tor Rustad
Guest
 
Posts: n/a
#10: Nov 3 '07

re: Variable Length


santosh wrote:
Quote:
Tor Rustad wrote:
Quote:
Quote:
>I don't have access to C89 std. here, but if memory serves me right,
>minimum of 8 initial characters was significant (external
>identifiers).
>
I think it was six initial characters and case insensitive too. A
concession to the limitations of some of the linkers back then.
Yes, 6 significant initial characters it was.

I beleave one of our major production systems, still have that
limitation. This limit resulted in some terrible naming conventions.

--
Tor <bwzcab@wvtqvm.vw | tr i-za-h a-z>
Malcolm McLean
Guest
 
Posts: n/a
#11: Nov 3 '07

re: Variable Length


"Tor Rustad" <tor_rustad@hotmail.comwrote in message
Quote:
>
Yes, 6 significant initial characters it was.
>
I beleave one of our major production systems, still have that
limitation. This limit resulted in some terrible naming conventions.
>
The rule of six.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

CBFalconer
Guest
 
Posts: n/a
#12: Nov 3 '07

re: Variable Length


James Kuyper wrote:
Quote:
lak wrote:
>
Quote:
>I want to know what is the variable length in c. I K&R they
>stated that atleast 31 character. But I give 1 lakhs length to
>a variable, but my compiler doesn't say any error. It accepts
>it. Then what is the maximum length to a variable name.?
>
The limit is on identifiers, not just variable names; function
names, for instance, are also identifiers.
>
The 31 character limit is only on external identifiers. Internal
identifiers have a limit of 63 (5.2.4p1).
>
That limit is a minimum, not a maximum. "There is no specific
limit on the maximum length of an identifier." (6.4.1p2).
That minimum, in C, depends on the standard in effect. For C89,
C90, C95 I believe it is smaller. However, in practice you can
always depend on 10 to 16 chars barring the use of ancient
compilers and linkers. Use of longer names is generally foolish.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com

Tor Rustad
Guest
 
Posts: n/a
#13: Nov 3 '07

re: Variable Length


Malcolm McLean wrote:
Quote:
"Tor Rustad" <tor_rustad@hotmail.comwrote in message
Quote:
>>
>Yes, 6 significant initial characters it was.
>>
>I beleave one of our major production systems, still have that
>limitation. This limit resulted in some terrible naming conventions.
>>
The rule of six.
Identifiers prefixed with letter + 5 digits, or 3 letters + 3 digits. :)

--
Tor <bwzcab@wvtqvm.vw | tr i-za-h a-z>
David Thompson
Guest
 
Posts: n/a
#14: Nov 19 '07

re: Variable Length


On Sat, 03 Nov 2007 10:32:18 -0700, Keith Thompson <kst-u@mib.org>
wrote:
Quote:
lak <lakindia89@gmail.comwrites:
Quote:
I want to know what is the variable length in c.
I K&R they stated that atleast 31 character.
But I give 1 lakhs length to a variable, but my compiler doesn't say
any error.
It accepts it.Then what is the maximum length to a variable name.?
>
The C90 standard requires compilers to support a minumum of 31
significant initial characters in an internal identifier or macro
name, 6 in an external identifier. I recall that external identifiers
that differ only in case ("foo" vs. "Foo") are not required to be
treated as distinct, but in a quick look at the C90 standard I didn't
find a reference to that.
>
6.1.2 under Implementation Limits
Quote:
C99 increases this to 63 characters for internal identifiers, 31 for
external identifiers. I believe that identifiers differing only in
case are required to be treated as distinct, but again, I didn't find
a reference to that in the standard (I'm sure it's there, I just
didn't take the time to find it).
>
It's no longer there explicitly; just the general statement in 6.4.2.1
that any difference within the limit (31 or 63) is a different
identifier, WITHOUT an exception for case-folding.
Quote:
However, compilers aren't required to impose these restrictions; <snip>
- formerly david.thompson1 || achar(64) || worldnet.att.net
Closed Thread