473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Variable Length

lak
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.?

Nov 3 '07 #1
13 7765
lak wrote:
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.
Nov 3 '07 #2
lak wrote:
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?

Nov 3 '07 #3
James Kuyper wrote:

[...]
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>

Nov 3 '07 #4
In article <fg**********@aioe.org>, santosh <sa*********@gmail.comwrote:
>lak wrote:
>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.

Nov 3 '07 #5
Tor Rustad wrote:
James Kuyper wrote:

[...]
>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.

Nov 3 '07 #6
Tor Rustad wrote:
James Kuyper wrote:

[...]
>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.
Nov 3 '07 #7

"lak" <la********@gmail.comwrote in message
>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
Nov 3 '07 #8
lak <la********@gmail.comwrites:
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) ks***@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"
Nov 3 '07 #9
santosh wrote:
Tor Rustad wrote:
>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 <bw****@wvtqvm.vw | tr i-za-h a-z>
Nov 3 '07 #10
"Tor Rustad" <to********@hotmail.comwrote in message
>
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

Nov 3 '07 #11
James Kuyper wrote:
lak wrote:
>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

Nov 3 '07 #12
Malcolm McLean wrote:
"Tor Rustad" <to********@hotmail.comwrote in message
>>
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 <bw****@wvtqvm.vw | tr i-za-h a-z>
Nov 3 '07 #13
On Sat, 03 Nov 2007 10:32:18 -0700, Keith Thompson <ks***@mib.org>
wrote:
lak <la********@gmail.comwrites:
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
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.
However, compilers aren't required to impose these restrictions; <snip>
- formerly david.thompson1 || achar(64) || worldnet.att.net
Nov 19 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
4
by: sylvain.loiseau | last post by:
Hello Given a node set, I try to compute the total of the string-length value of each node. For instance, with : <xsl:for-each select="//q"> <!-- the length of each node is compute with:...
5
by: MLH | last post by:
I'm working with lots of long strings now, it seems. I have to import them & parse them constantly. The A97 memo field type supports only 32768 chars. What happens when this is processed... Dim...
5
by: dam_fool_2003 | last post by:
Hai, I studied that the array size is fixed. But I come across a word called "variable length array". Is it possible to change the array size? So I tried the following: #include<stdio.h>...
18
by: Panchal V | last post by:
I want to access a variable length record in C, the format is as follows : +---+---+-----------+ | A | L | D A T A | +---+---+-----------+ A - Some Data (1 BYTE) L - Length the Data that...
14
by: Luiz Antonio Gomes Pican?o | last post by:
How i can store a variable length data in file ? I want to do it using pure C, without existing databases. I'm thinking to use pages to store data. Anyone has idea for the file format ? I...
19
by: Skybuck Flying | last post by:
Hi, I think I might have just invented the variable bit cpu :) It works simply like this: Each "data bit" has a "meta data bit". The meta data bit describes if the bit is the ending bit...
8
by: chellappa | last post by:
hi Everybody ! decalaring variable in a.h and using that vaaariable in a1.c and inalization is in main.c it is possible .........pleaase correct that error is it Possible? i am trying it...
6
by: foreverbored75 | last post by:
Hello All! I am just learning c++ in school and I have the following question: Is there a way for the user to input the length of an array (console application) without using another variable?...
3
by: chandra.krothapalli | last post by:
Hi, I am writing a program to read database logs using db2Readlog/ db2ReadLogNoConn API. I am able to parse the data of "FIXED format data" and link them to appropriate columns for a given...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.