Static Var in Struct....

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

    #1

    Static Var in Struct....

    Can A C Program having static Variable in Structure is possible.....

    i.e.

    struct A
    {
    int a;
    static int b;
    };

    if yes then how to access this static variable.....

    As we done in C++ with A::b{i.e. using Scope Resolution}

  • Jack Klein

    #2
    Re: Static Var in Struct....

    On 16 Mar 2005 22:03:26 -0800, "Raxit" <raxitsheth@gma il.com> wrote in
    comp.lang.c:
    [color=blue]
    > Can A C Program having static Variable in Structure is possible.....[/color]

    No.
    [color=blue]
    > i.e.
    >
    > struct A
    > {
    > int a;
    > static int b;[/color]

    The members of a structure can't have storage class specifiers.
    Objects of the structure type can, but they apply to all of the
    members.
    [color=blue]
    > };
    >
    > if yes then how to access this static variable.....
    >
    > As we done in C++ with A::b{i.e. using Scope Resolution}[/color]

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
    alt.comp.lang.l earn.c-c++

    Comment

    • Raxit

      #3
      Re: Static Var in Struct....

      I want to know...the logical Reason Why not allowing Structure has
      Static Member....

      Raxit

      Comment

      • CBFalconer

        #4
        Re: Static Var in Struct....

        Raxit wrote:[color=blue]
        >
        > I want to know...the logical Reason Why not allowing Structure has
        > Static Member....[/color]

        Are you asking this again because you didn't like Jacks answer, and
        is that why you didn't bother to quote anything from his answer?
        Is there any connection with the strange and annoying sentence
        construction you use? Surely by now you have figured out how to
        use Google, if not try my sig. below.

        --
        "If you want to post a followup via groups.google.c om, don't use
        the broken "Reply" link at the bottom of the article. Click on
        "show options" at the top of the article, then click on the
        "Reply" at the bottom of the article headers." - Keith Thompson

        Comment

        • Chris Dollin

          #5
          Re: Static Var in Struct....

          Raxit wrote:
          [color=blue]
          > I want to know...the logical Reason Why not allowing Structure has
          > Static Member....[/color]

          What counts as a logical reason?

          Here's a possible reason: in C, there's little advantage to be
          gained by allowing it. (Just declare a Plain Old Static Variable.)

          You might say "But I want the name to hide in the struct namespace!".

          I say back, "Dude, if you want namespacey things in C, there are
          things you could do with *lots* more payback than static structure
          members."

          --
          Chris "logical hedgehog" Dollin

          Comment

          • Grumble

            #6
            Re: Static Var in Struct....

            CBFalconer wrote:
            [color=blue]
            > Raxit wrote:
            >[color=green]
            >> I want to know...the logical Reason Why not allowing Structure has
            >> Static Member....[/color]
            >
            > Are you asking this again because you didn't like Jacks answer, and
            > is that why you didn't bother to quote anything from his answer?
            > Is there any connection with the strange and annoying sentence
            > construction you use?[/color]

            He is posting from India (NNTP-Posting-Host: 202.149.200.69) .
            Perhaps English is not his mother tongue?

            AFAICT, he's asking for a rationale.

            --
            Regards, Grumble

            Comment

            • CBFalconer

              #7
              Re: Static Var in Struct....

              Grumble wrote:[color=blue]
              > CBFalconer wrote:[color=green]
              >> Raxit wrote:
              >>[color=darkred]
              >>> I want to know...the logical Reason Why not allowing Structure has
              >>> Static Member....[/color]
              >>
              >> Are you asking this again because you didn't like Jacks answer, and
              >> is that why you didn't bother to quote anything from his answer?
              >> Is there any connection with the strange and annoying sentence
              >> construction you use?[/color]
              >
              > He is posting from India (NNTP-Posting-Host: 202.149.200.69) .
              > Perhaps English is not his mother tongue?
              >
              > AFAICT, he's asking for a rationale.[/color]

              Maybe I am made over grouchy by the foolish use of the broken
              google interface, and the total lack of quotations. Especially
              when it is unnecessary and I and others have been campaigning to
              show how to beat it.

              To answer him, a structure is a single entity, to be stored
              somewhere. Static specifies the class of storage involved. It is
              not feasible to store one portion one place and another elsewhere
              and maintain the ability to handle it as a unit.

              --
              "If you want to post a followup via groups.google.c om, don't use
              the broken "Reply" link at the bottom of the article. Click on
              "show options" at the top of the article, then click on the
              "Reply" at the bottom of the article headers." - Keith Thompson


              Comment

              • Tor Rustad

                #8
                Re: Static Var in Struct....

                "Raxit" <raxitsheth@gma il.com> wrote in message
                [color=blue]
                > I want to know...the logical Reason Why not allowing
                > Structure has Static Member....[/color]

                Well, if that wasn't there from the beginning, the logical
                reason should rather be given the other way around:

                1. Why introduce static struct member?
                2. Will it break existing code?


                BTW. I have no idea what "static struct member" is
                in C++. :-)

                --
                Tor <torust AT online DOT no>

                Comment

                Working...