variable allocated from stack/bss ??

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

    variable allocated from stack/bss ??

    Given the following code & variable i .

    int main(int argc,char **argv){
    int i;
    printf("%d\n",i );
    return 0;
    }

    here i is allocated from bss or stack ?

    I think it is stack,because it prints garbage value; If it were
    allocated from bss the default value would be 0
    please tell me if I am right or wrong ??

  • MQ

    #2
    Re: variable allocated from stack/bss ??


    onkar wrote:
    Given the following code & variable i .
    >
    int main(int argc,char **argv){
    int i;
    printf("%d\n",i );
    return 0;
    }
    >
    here i is allocated from bss or stack ?
    >
    I think it is stack,because it prints garbage value; If it were
    allocated from bss the default value would be 0
    please tell me if I am right or wrong ??
    Local variables are stored on the stack. BSS is used for uninitialized
    global or static variables.

    Comment

    • Richard Heathfield

      #3
      Re: variable allocated from stack/bss ??

      MQ said:

      <snip>
      Local variables are stored on the stack.
      C&V please.
      BSS is used for uninitialized
      global or static variables.
      C&V please.

      --
      Richard Heathfield
      "Usenet is a strange place" - dmr 29/7/1999

      email: rjh at the above domain, - www.

      Comment

      • Richard Heathfield

        #4
        Re: variable allocated from stack/bss ??

        onkar said:
        Given the following code & variable i .
        >
        int main(int argc,char **argv){
        int i;
        printf("%d\n",i );
        return 0;
        }
        >
        here i is allocated from bss or stack ?
        The C Standard doesn't require your implementation to have a bss or a stack.
        It does require, however, that you provide a proper prototype for printf,
        and it also requires that you don't evaluate indeterminately-valued
        objects.

        --
        Richard Heathfield
        "Usenet is a strange place" - dmr 29/7/1999

        email: rjh at the above domain, - www.

        Comment

        • santosh

          #5
          Re: variable allocated from stack/bss ??

          onkar wrote:
          Given the following code & variable i .
          >
          int main(int argc,char **argv){
          int i;
          printf("%d\n",i );
          return 0;
          }
          >
          here i is allocated from bss or stack ?
          >
          I think it is stack,because it prints garbage value; If it were
          allocated from bss the default value would be 0
          please tell me if I am right or wrong ??
          The C standard doesn't specify the exact places where variables of
          different types are stored. It just specifies their scope,
          implementations are free to do whatever they want behind the scenes, as
          long as all the necessary semantics are maintained.

          Coming to your off-topic question, the short answer is yes, on most
          implementations .

          Comment

          • Martin Ambuhl

            #6
            Re: variable allocated from stack/bss ??

            onkar wrote:
            Given the following code & variable i .
            >
            int main(int argc,char **argv){
            int i;
            printf("%d\n",i );
            return 0;
            }
            >
            here i is allocated from bss or stack ?
            >
            I think it is stack,because it prints garbage value; If it were
            allocated from bss the default value would be 0
            please tell me if I am right or wrong ??
            Neither 'bss' nor 'stack' have any meaning in C. All we can say is that
            'i' is an uninitialized automatic variable, and so has an indeterminate
            initial value. If your implementation has some segment of memory
            initialized to zero -- and that is by no means a given -- then it may,
            or may not, use parts of that for some automatic variables. The
            mechanism is completely up to the implementation.

            Comment

            • Martin Ambuhl

              #7
              Re: variable allocated from stack/bss ??

              MQ wrote:
              onkar wrote:
              >Given the following code & variable i .
              >>
              >int main(int argc,char **argv){
              > int i;
              > printf("%d\n",i );
              > return 0;
              >}
              >>
              >here i is allocated from bss or stack ?
              >>
              >I think it is stack,because it prints garbage value; If it were
              >allocated from bss the default value would be 0
              >please tell me if I am right or wrong ??
              >
              Local variables are stored on the stack. BSS is used for uninitialized
              global or static variables.
              There is no such requirement for an implementation of the C programming
              language. There is, in fact, no requirement for things called 'stack'
              or 'BSS' to even exist. Please don't give such foolish and incorrect
              'answers'. They only show your limited experience and lack of
              qualification to give meaningful answers.

              Comment

              • jacob navia

                #8
                Re: variable allocated from stack/bss ??

                Martin Ambuhl wrote:
                onkar wrote:
                >
                >Given the following code & variable i .
                >>
                >int main(int argc,char **argv){
                > int i;
                > printf("%d\n",i );
                > return 0;
                >}
                >>
                >here i is allocated from bss or stack ?
                >>
                >I think it is stack,because it prints garbage value; If it were
                >allocated from bss the default value would be 0
                >please tell me if I am right or wrong ??
                >
                >
                Neither 'bss' nor 'stack' have any meaning in C. All we can say is that
                'i' is an uninitialized automatic variable, and so has an indeterminate
                initial value. If your implementation has some segment of memory
                initialized to zero -- and that is by no means a given -- then it may,
                or may not, use parts of that for some automatic variables. The
                mechanism is completely up to the implementation.
                >
                Translation:

                In some weird implementation that could exist somewhere there is no
                stack and no bss. Since I want to be pedantic I will generalize then
                to say that "The C language dfoesn't require a stack" even if I know
                that 99% of all the implementations in work stations today use
                exactly those.

                Comment

                • jacob navia

                  #9
                  Re: variable allocated from stack/bss ??

                  onkar wrote:
                  Given the following code & variable i .
                  >
                  int main(int argc,char **argv){
                  int i;
                  printf("%d\n",i );
                  return 0;
                  }
                  >
                  here i is allocated from bss or stack ?
                  >
                  I think it is stack,because it prints garbage value; If it were
                  allocated from bss the default value would be 0
                  please tell me if I am right or wrong ??
                  >
                  Yes, you are right

                  Comment

                  • Richard Heathfield

                    #10
                    Re: variable allocated from stack/bss ??

                    jacob navia said:
                    onkar wrote:
                    >Given the following code & variable i .
                    >>
                    >int main(int argc,char **argv){
                    > int i;
                    > printf("%d\n",i );
                    > return 0;
                    >}
                    >>
                    >here i is allocated from bss or stack ?
                    >>
                    >I think it is stack,because it prints garbage value; If it were
                    >allocated from bss the default value would be 0
                    >please tell me if I am right or wrong ??
                    >>
                    >
                    Yes, you are right
                    Chapter and verse, please.

                    --
                    Richard Heathfield
                    "Usenet is a strange place" - dmr 29/7/1999

                    email: rjh at the above domain, - www.

                    Comment

                    • jacob navia

                      #11
                      Re: variable allocated from stack/bss ??

                      Richard Heathfield wrote:
                      jacob navia said:
                      >
                      >
                      >>onkar wrote:
                      >>
                      >>>Given the following code & variable i .
                      >>>
                      >>>int main(int argc,char **argv){
                      >> int i;
                      >> printf("%d\n",i );
                      >> return 0;
                      >>>}
                      >>>
                      >>>here i is allocated from bss or stack ?
                      >>>
                      >>>I think it is stack,because it prints garbage value; If it were
                      >>>allocated from bss the default value would be 0
                      >>>please tell me if I am right or wrong ??
                      >>>
                      >>
                      >>Yes, you are right
                      >
                      >
                      Chapter and verse, please.
                      >
                      Since bss variables are initialized to zero (the standard does not
                      name them "bss" of course but it requires that uninitialized
                      variables be initilaized to zero), that variable CAN'T be an
                      uninitialized variable in that sense. That mens is an automatic
                      variable allocated in temporary storage. This storage is normally
                      the stack in most implementations

                      Comment

                      • Richard Heathfield

                        #12
                        Re: variable allocated from stack/bss ??

                        jacob navia said:
                        Richard Heathfield wrote:
                        >jacob navia said:
                        >>
                        >>
                        >>>onkar wrote:
                        >>>
                        >>>>Given the following code & variable i .
                        >>>>
                        >>>>int main(int argc,char **argv){
                        >>> int i;
                        >>> printf("%d\n",i );
                        >>> return 0;
                        >>>>}
                        >>>>
                        >>>>here i is allocated from bss or stack ?
                        >>>>
                        >>>>I think it is stack,because it prints garbage value; If it were
                        >>>>allocated from bss the default value would be 0
                        >>>>please tell me if I am right or wrong ??
                        >>>>
                        >>>
                        >>>Yes, you are right
                        >>
                        >>
                        >Chapter and verse, please.
                        >>
                        >
                        Since bss variables
                        Where does the Standard define these?
                        are initialized to zero (the standard does not
                        name them "bss" of course but it requires that uninitialized
                        variables be initilaized to zero),
                        It says no such thing.


                        #include <stdio.h>

                        int main(void)
                        {
                        int bss;

                        You seem to be claiming that this "bss variable" must be initialised to 0.
                        If so, you're wrong.

                        --
                        Richard Heathfield
                        "Usenet is a strange place" - dmr 29/7/1999

                        email: rjh at the above domain, - www.

                        Comment

                        • jacob navia

                          #13
                          Re: variable allocated from stack/bss ??

                          Richard Heathfield wrote:
                          jacob navia said:
                          >
                          >
                          >>Richard Heathfield wrote:
                          >>
                          >>>jacob navia said:
                          >>>
                          >>>
                          >>>
                          >>>>onkar wrote:
                          >>>>
                          >>>>
                          >>>>>Given the following code & variable i .
                          >>>>>
                          >>>>>int main(int argc,char **argv){
                          >>>> int i;
                          >>>> printf("%d\n",i );
                          >>>> return 0;
                          >>>>>}
                          >>>>>
                          >>>>>here i is allocated from bss or stack ?
                          >>>>>
                          >>>>>I think it is stack,because it prints garbage value; If it were
                          >>>>>allocate d from bss the default value would be 0
                          >>>>>please tell me if I am right or wrong ??
                          >>>>>
                          >>>>
                          >>>>Yes, you are right
                          >>>
                          >>>
                          >>>Chapter and verse, please.
                          >>>
                          >>
                          >>Since bss variables
                          >
                          >
                          Where does the Standard define these?
                          >
                          >
                          >>are initialized to zero (the standard does not
                          >>name them "bss" of course but it requires that uninitialized
                          >>variables be initilaized to zero),
                          >
                          >
                          It says no such thing.
                          >
                          >
                          #include <stdio.h>
                          >
                          int main(void)
                          {
                          int bss;
                          >
                          You seem to be claiming that this "bss variable" must be initialised to 0.
                          If so, you're wrong.
                          >
                          What?
                          Can't you read?
                          I said that that wasn't a bss variable because (precisely) is not
                          cleared to zero.

                          Comment

                          • Richard Heathfield

                            #14
                            Re: variable allocated from stack/bss ??

                            jacob navia said:
                            Richard Heathfield wrote:
                            <snip>
                            >int main(void)
                            >{
                            > int bss;
                            >>
                            >You seem to be claiming that this "bss variable" must be initialised to
                            >0. If so, you're wrong.
                            >>
                            >
                            What?
                            Can't you read?
                            Sure. Can you?
                            I said that that wasn't a bss variable because (precisely) is not
                            cleared to zero.
                            No, the object's failure to get a default static initialiser value does not,
                            as you claim, imply that it's a "bss variable" (for which you have yet to
                            provide a reference to the Standard's definition); rather, it implies that
                            the object doesn't have static storage duration and is not a sub-member of
                            a partly-initialised aggregate object.

                            --
                            Richard Heathfield
                            "Usenet is a strange place" - dmr 29/7/1999

                            email: rjh at the above domain, - www.

                            Comment

                            • Al Balmer

                              #15
                              Re: variable allocated from stack/bss ??

                              On Wed, 29 Nov 2006 13:54:23 +0000, Richard Heathfield
                              <rjh@see.sig.in validwrote:
                              >jacob navia said:
                              >
                              >Richard Heathfield wrote:
                              >
                              ><snip>
                              >
                              >>int main(void)
                              >>{
                              >> int bss;
                              >>>
                              >>You seem to be claiming that this "bss variable" must be initialised to
                              >>0. If so, you're wrong.
                              >>>
                              >>
                              >What?
                              >Can't you read?
                              >
                              >Sure. Can you?
                              >
                              >I said that that wasn't a bss variable because (precisely) is not
                              >cleared to zero.
                              >
                              >No, the object's failure to get a default static initialiser value does not,
                              >as you claim, imply that it's a "bss variable" (for which you have yet to
                              >provide a reference to the Standard's definition); rather, it implies that
                              >the object doesn't have static storage duration and is not a sub-member of
                              >a partly-initialised aggregate object.
                              I'm only seeing one side of this discussion, but now I'm curious. Has
                              Jacob invented a new type of variable called "bss"? In my assembler
                              coding days, "bss" meant "block storage symbol" and was implemented by
                              simply incrementing the program counter by the requested amount, which
                              of course had no effect on memory thus skipped.

                              --
                              Al Balmer
                              Sun City, AZ

                              Comment

                              Working...