Variable Length

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lak

    #1

    Variable Length

    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

    #2
    Re: Variable Length

    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.

    Comment

    • santosh

      #3
      Re: Variable Length

      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?

      Comment

      • Tor Rustad

        #4
        Re: Variable Length

        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>

        Comment

        • Kenny McCormack

          #5
          Re: Variable Length

          In article <fghu1k$f9t$2@a ioe.org>, santosh <santosh.k83@gm ail.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.

          Comment

          • santosh

            #6
            Re: Variable Length

            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.

            Comment

            • James Kuyper

              #7
              Re: Variable Length

              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.

              Comment

              • Malcolm McLean

                #8
                Re: Variable Length


                "lak" <lakindia89@gma il.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.



                Comment

                • Keith Thompson

                  #9
                  Re: Variable Length

                  lak <lakindia89@gma il.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_ident ifier
                  and
                  this_is_a_very_ very_long_ident ical 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_Keit h) 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"

                  Comment

                  • Tor Rustad

                    #10
                    Re: Variable Length

                    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 <bwzcab@wvtqvm. vw | tr i-za-h a-z>

                    Comment

                    • Malcolm McLean

                      #11
                      Re: Variable Length

                      "Tor Rustad" <tor_rustad@hot mail.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.


                      Comment

                      • CBFalconer

                        #12
                        Re: Variable Length

                        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

                        Comment

                        • Tor Rustad

                          #13
                          Re: Variable Length

                          Malcolm McLean wrote:
                          "Tor Rustad" <tor_rustad@hot mail.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 <bwzcab@wvtqvm. vw | tr i-za-h a-z>

                          Comment

                          • David Thompson

                            #14
                            Re: Variable Length

                            On Sat, 03 Nov 2007 10:32:18 -0700, Keith Thompson <kst-u@mib.org>
                            wrote:
                            lak <lakindia89@gma il.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.ne t

                            Comment

                            Working...