size of memory in C -- allocation

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

    size of memory in C -- allocation

    Got Confused on the interview with memory alligment questions... PLEASE
    HELP -- How much bytes of memory will structs below take on 32 bit
    machine? What about 64 bit machine? Why is it different? (if it's
    relevent, use standard size of datatypes)


    a)

    Code:
    struct
    {
    short int a;
    int b;
    };





    b)
    Code:
    struct{
    short int a;
    int b;
    int somefunc();
    virtual int func1();
    };






    c) Very Tricky (Hint: it is tricky with virtual function (or should I
    say pointers to vtable...you should know something about vtables in
    last but clever case))

    Code:
    struct{
    short int a;
    int b;
    virtual int func_1();
    virtual int func_2();
    :
    :
    virtual int func_n();
    };

  • Mike Wahler

    #2
    Re: size of memory in C -- allocation

    "puzzlecrac ker" <ironsel2000@gm ail.com> wrote in message
    news:1106074151 .862892.135790@ c13g2000cwb.goo glegroups.com.. .[color=blue]
    > Got Confused on the interview with memory alligment questions... PLEASE
    > HELP -- How much bytes of memory will structs below take on 32 bit
    > machine?
    > What about 64 bit machine?[/color]

    This depends entirely upon the compiler. The language
    only requires that the memory is sufficient to store
    all the members.
    [color=blue]
    > Why is it different?[/color]

    Because machines are different (and thus compilers for
    them will do things differently).
    [color=blue]
    > (if it's
    > relevent, use standard size of datatypes)[/color]

    Data types (except for the character types) don't have
    a 'standard size', only a 'minimum size'. The character
    types all have a size of one byte, by definition.
    [color=blue]
    > a)
    >
    > Code:
    > struct
    > {
    > short int a;
    > int b;
    > };
    >
    > b)
    > Code:
    > struct{
    > short int a;
    > int b;
    > int somefunc();
    > virtual int func1();
    > };
    >
    > c) Very Tricky (Hint: it is tricky with virtual function (or should I
    > say pointers to vtable...you should know something about vtables in
    > last but clever case))[/color]

    C does not have virtual functions. C++ does.
    However, 'vtables' are not part of the C++ language,
    but an implementation detail, not required to be
    used at all.

    Are you aware that C and C++ are two separate, distinct
    languages, and that while they share similar syntax,
    there are significant differences? Does the interviewer
    know this?

    -Mike



    Comment

    • pete

      #3
      Re: size of memory in C -- allocation

      puzzlecracker wrote:
      [color=blue]
      > virtual function[/color]

      Try news:comp.lang. c++

      --
      pete

      Comment

      • Thomas Matthews

        #4
        Re: size of memory in C -- allocation

        puzzlecracker wrote:[color=blue]
        > Got Confused on the interview with memory alligment questions... PLEASE
        > HELP -- How much bytes of memory will structs below take on 32 bit
        > machine? What about 64 bit machine? Why is it different? (if it's
        > relevent, use standard size of datatypes)[/color]

        [snip]
        And you can't do this yourself?
        Have you read the replies to a similar post?

        [color=blue]
        > a)
        >
        > Code:
        > struct
        > {
        > short int a;
        > int b;
        > };[/color]

        How big is a "short int"?
        On 32-bit platforms, some have 16-bit shorts and some
        have 32-bit short ints.

        Let us assume that the processor only fetches at
        32-bit address locations, that is every 4 bytes in
        common notation. We'll also assume that a short int
        is 16-bits (2 bytes).

        To make life easier, we well declare a variable of
        the above structure and allocate it at address 0x00.
        Let us assign the value 0x1616 to the 'a' member and
        0x32323232 to the 'b' member. We'll also use Big
        Endian notation.

        Address Value
        ------- -----
        0100 1616 -- member 'a'
        0102* 3232323232 -- member 'b'
        0106* 0000 -- unknown value in memory.

        Since this processor only fetches at 4 byte boundaries,
        it will fetch at addresses 0x100 and 0x104. The address
        of 0x102 cannot be accessed directly and is out of
        alignment. The actual values for 'a' and 'b' might
        be: a == 0x16163232, b == 0x32320000

        The compiler is allowed to add padding between members
        so that the values are placed at locations where the
        processor can fetch them correctly:

        0x100 1616 -- member 'a'
        0x102 0000 -- padding from the compiler.
        0x104 32323232 -- member ' b'

        The above layout allows the processor to fetch the
        value 0x1616 at location 0x100 and 0x32323232 at
        location 0x104.

        The exercise of a 64-bit machine is left to the
        reader. Hint: a 64-bit machine likes to fetch
        at every 8 bytes; and assume a short int is either
        16 or 32 bits.

        [color=blue]
        >
        > b)
        > Code:
        > struct{
        > short int a;
        > int b;
        > int somefunc();
        > virtual int func1();
        > };[/color]

        Similar problem as above. However, this time use
        pointers instead of the functions above. You could
        assume that a 32-bit processor has a 32-bit pointer,
        and a 64-bit processor has a 64-bit pointer.

        [color=blue]
        > c) Very Tricky (Hint: it is tricky with virtual function (or should I
        > say pointers to vtable...you should know something about vtables in
        > last but clever case))
        >
        > Code:
        > struct{
        > short int a;
        > int b;
        > virtual int func_1();
        > virtual int func_2();
        > :
        > :
        > virtual int func_n();
        > };
        >[/color]

        VTables are not required per the standard. So this
        question can be thrown out. But in the spirit of the
        question, one could assume that the vtable is just an
        array of pointers. See question 'b'.

        For some extra practice, consider these structs:
        struct A
        {
        char c;
        short int si;
        int j;
        char d
        int i;
        };

        struct B
        {
        int i;
        short int si;
        char c;
        char d;
        int j;
        };

        --
        Thomas Matthews

        C++ newsgroup welcome message:

        C++ Faq: http://www.parashift.com/c++-faq-lite
        C Faq: http://www.eskimo.com/~scs/c-faq/top.html
        alt.comp.lang.l earn.c-c++ faq:

        Other sites:
        http://www.josuttis.com -- C++ STL Library book
        http://www.sgi.com/tech/stl -- Standard Template Library

        Comment

        • Jonathan Bartlett

          #5
          Re: size of memory in C -- allocation

          puzzlecracker wrote:[color=blue]
          > Got Confused on the interview with memory alligment questions... PLEASE
          > HELP -- How much bytes of memory will structs below take on 32 bit
          > machine? What about 64 bit machine? Why is it different? (if it's
          > relevent, use standard size of datatypes)[/color]

          It actually depends on the compiler, really, although you can compute
          minimums for 32 and 64 bit machines. The compiler can also add padding
          however it wishes.

          As for the virtual functions, remember that this is a C newsgroup, not a
          C++ newsgroup. But just for fun in the structs themselves the vtable
          only takes up one word of memory no matter how big it is, because its
          just a pointer to a vtable -- the vtable is allocated once for the
          entire class.

          Jon
          ----
          Learn to program using Linux assembly language

          Comment

          • puzzlecracker

            #6
            Re: size of memory in C -- allocation

            Let me know if i solved your examples right, on 32 and 64 bit machine.
            If not, please explain where I made a mistake.
            [color=blue]
            >The exercise of a 64-bit machine is left to the
            >reader. Hint: a 64-bit machine likes to fetch
            >at every 8 bytes; and assume a short int is either
            >16 or 32 bits.[/color]

            since short int is 2 bytes and int is 4 bytes, it will occupy a block
            of 8 byte, so the total size is 8 byte.


            2)[color=blue]
            >struct A
            >{
            > char c;
            >short int si;
            > int j;
            > char d
            > int i;
            >};[/color]

            32 bit machine:
            -----------------
            1st block: s, si +padding = 4 bytes
            2nd block: j = 4 bytes
            3rd block: d+padding = 4 bytes
            4th block: i = 4 bytes
            -----------------------------------
            TOTAL: = 16 bytes


            64 bit Machine
            ----------------
            1st block: s,si j+d = 8byte
            2nd block i+padding = 8byte
            ------------------------------
            TOTAL: 16 bytes



            2)[color=blue]
            >struct B
            >{
            > int i;
            > short int si;
            > char c;
            > char d;
            > int j;
            >};[/color]

            32 bit machine
            --------------
            1st block: i = 4 bytes
            2rd block: s1, c d = 4 bytes
            4th block j = 4 bytes
            -----------------------------------
            TOTAL: 12 bytes

            64 bit Machine
            ----------------
            1st block: i, si c + d = 8 byte
            2nd block j = 8 byte
            ---------------------------------
            TOTAL: = 16 bytes

            =============== =============== =============== ============


            small question: virutal functions, regular fucntions and inline
            functions take the same space (ex: 4 bytes or 8 bytes 32 and 64 bits
            respectively)? According to alignement rules: compiler is tring to fit
            as many variable (data types) as possible in each block for as long as
            it fits entirely or else adds padding... is that the correct way of
            thinking?



            Thanks...

            ...Puzzlecracke r!

            Comment

            • Chris Croughton

              #7
              Re: size of memory in C -- allocation

              On 18 Jan 2005 10:49:11 -0800, puzzlecracker
              <ironsel2000@gm ail.com> wrote:
              [color=blue]
              > Got Confused on the interview with memory alligment questions... PLEASE
              > HELP -- How much bytes of memory will structs below take on 32 bit
              > machine?[/color]

              Some machine and compiler dependant number. Since you don't say what
              machine and compiler it is impossible to give an answer.
              [color=blue]
              > What about 64 bit machine? Why is it different? (if it's
              > relevent, use standard size of datatypes)[/color]
              [color=blue]
              > struct
              > {
              > short int a;
              > int b;
              > };[/color]

              No fewer than 32 bits, could be quite a lot more. The standard requires
              a short int to hold at least 16 bits and an int to hold at least 16
              bits. On a 32 bit machine an int may commonly be 32 bits, on a 64 bit
              machine it could be 32 or 64 bits commonly. Then you may have alignment
              requirements, some machines can only access 32 bit variables starting on
              a 32 bit boundary so padding will have to be added between the
              variables. Similarly for 64 bit variables. Then there may be a
              requirement that all structs are padded to (say) a 128 bit boundary.
              [color=blue]
              > struct{
              > short int a;
              > int b;
              > int somefunc();
              > virtual int func1();
              > };[/color]

              Zero bits, it has a compilation error ('virtual' is not a C keyword).
              [color=blue]
              > c) Very Tricky (Hint: it is tricky with virtual function (or should I
              > say pointers to vtable...you should know something about vtables in
              > last but clever case))[/color]

              What's a vtable in C? The word doesn't exist in ISO/IEC-9899 (the C
              specification). Nor does 'virtual', so the answer is that it takes no
              space again because it won't compile.

              Chris C

              Comment

              • CBFalconer

                #8
                Re: size of memory in C -- allocation

                puzzlecracker wrote:[color=blue]
                >
                > Got Confused on the interview with memory alligment questions... PLEASE
                > HELP -- How much bytes of memory will structs below take on 32 bit
                > machine? What about 64 bit machine? Why is it different? (if it's
                > relevent, use standard size of datatypes)
                >
                > a)
                >
                > Code:
                > struct
                > {
                > short int a;
                > int b;
                > };[/color]

                They forgot to give the struct a label. The answer then is

                sizeof(struct x)

                which may very well be 2 * sizeof(int)

                and you cannot be any more accurate without seeing limits.h.
                Otherwise it is just a guess. Even with limits.h it will be a
                guess, but an educated one. sizeof is the only accurate means of
                measuring it.
                [color=blue]
                >
                > b)
                > Code:
                > struct{
                > short int a;
                > int b;
                > int somefunc();
                > virtual int func1();
                > };
                >
                > c) Very Tricky (Hint: it is tricky with virtual function (or should I
                > say pointers to vtable...you should know something about vtables in
                > last but clever case))
                >
                > Code:
                > struct{
                > short int a;
                > int b;
                > virtual int func_1();
                > virtual int func_2();
                > :
                > :
                > virtual int func_n();
                > };[/color]

                The "virtual" is a syntax error. Again the struct is missing a
                label, and the answer to a applies.

                --
                "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

                • puzzlecracker

                  #9
                  Re: size of memory in C -- allocation

                  > The "virtual" is a syntax error. Again the struct is missing a[color=blue]
                  > label, and the answer to a applies.[/color]

                  Ok, let's refer to C++ struct - yes this is topic off, but I didn't get
                  sufficient anwer in different group and this group seem to be most
                  valuable given that the question is somewhat related.

                  puzzlecracker Jan 18, 12:40 pm show options

                  Newsgroups: comp.lang.c
                  From: "puzzlecrac ker" <ironsel2...@gm ail.com> - Find messages by this
                  author
                  Date: 18 Jan 2005 12:40:16 -0800
                  Local: Tues, Jan 18 2005 12:40 pm
                  Subject: Re: size of memory in C -- allocation
                  Reply | Reply to Author | Forward | Print | Individual Message | Show
                  original | Remove | Report Abuse

                  Let me know if i solved your examples right, on 32 and 64 bit machine.
                  If not, please explain where I made a mistake.


                  [color=blue]
                  >The exercise of a 64-bit machine is left to the
                  >reader. Hint: a 64-bit machine likes to fetch
                  >at every 8 bytes; and assume a short int is either
                  >16 or 32 bits.[/color]


                  since short int is 2 bytes and int is 4 bytes, it will occupy a block
                  of 8 byte, so the total size is 8 byte.

                  2)


                  [color=blue]
                  >struct A
                  >{
                  > char c;
                  >short int si;
                  > int j;
                  > char d
                  > int i;
                  >};[/color]


                  32 bit machine:
                  -----------------
                  1st block: s, si +padding = 4 bytes
                  2nd block: j = 4 bytes
                  3rd block: d+padding = 4 bytes
                  4th block: i = 4 bytes
                  -----------------------------------
                  TOTAL: = 16 bytes

                  64 bit Machine
                  ----------------
                  1st block: s,si j+d = 8byte
                  2nd block i+padding = 8byte
                  ------------------------------
                  TOTAL: 16 bytes


                  2)


                  [color=blue]
                  >struct B
                  >{
                  > int i;
                  > short int si;
                  > char c;
                  > char d;
                  > int j;
                  >};[/color]


                  32 bit machine
                  --------------
                  1st block: i = 4 bytes
                  2rd block: s1, c d = 4 bytes
                  4th block j = 4 bytes
                  -----------------------------------
                  TOTAL: 12 bytes

                  64 bit Machine
                  ----------------
                  1st block: i, si c + d = 8 byte
                  2nd block j = 8 byte
                  ---------------------------------
                  TOTAL: = 16 bytes


                  =============== =============== =============== ============


                  Small question: virutal functions, regular functions and inline
                  functions take the same space (ex: 4 bytes or 8 bytes 32 and 64 bits
                  respectively)? According to alignement rules: compiler is tring to fit
                  as many variable (data types) as possible in each block for as long as
                  it fits entirely or else adds padding... is that the correct way of
                  thinking?

                  Also, is function in the struct represented as a pointer and takes its
                  respective size?

                  Thanks...


                  ...Puzzlecracke r!

                  Comment

                  • puzzlecracker

                    #10
                    Re: size of memory in C -- allocation

                    puzzlecracker Jan 18, 12:40 pm show options

                    Newsgroups: comp.lang.c
                    From: "puzzlecrac ker" <ironsel2...@gm ail.com> - Find messages by this
                    author
                    Date: 18 Jan 2005 12:40:16 -0800
                    Local: Tues, Jan 18 2005 12:40 pm
                    Subject: Re: size of memory in C -- allocation
                    Reply | Reply to Author | Forward | Print | Individual Message | Show
                    original | Remove | Report Abuse

                    Let me know if i solved your examples right, on 32 and 64 bit machine.
                    If not, please explain where I made a mistake.


                    [color=blue]
                    >The exercise of a 64-bit machine is left to the
                    >reader. Hint: a 64-bit machine likes to fetch
                    >at every 8 bytes; and assume a short int is either
                    >16 or 32 bits.[/color]


                    since short int is 2 bytes and int is 4 bytes, it will occupy a block
                    of 8 byte, so the total size is 8 byte.

                    2)


                    [color=blue]
                    >struct A
                    >{
                    > char c;
                    >short int si;
                    > int j;
                    > char d
                    > int i;
                    >};[/color]


                    32 bit machine:
                    -----------------
                    1st block: s, si +padding = 4 bytes
                    2nd block: j = 4 bytes
                    3rd block: d+padding = 4 bytes
                    4th block: i = 4 bytes
                    -----------------------------------
                    TOTAL: = 16 bytes

                    64 bit Machine
                    ----------------
                    1st block: s,si j+d = 8byte
                    2nd block i+padding = 8byte
                    ------------------------------
                    TOTAL: 16 bytes


                    2)


                    [color=blue]
                    >struct B
                    >{
                    > int i;
                    > short int si;
                    > char c;
                    > char d;
                    > int j;
                    >};[/color]


                    32 bit machine
                    --------------
                    1st block: i = 4 bytes
                    2rd block: s1, c d = 4 bytes
                    4th block j = 4 bytes
                    -----------------------------------
                    TOTAL: 12 bytes

                    64 bit Machine
                    ----------------
                    1st block: i, si c + d = 8 byte
                    2nd block j = 8 byte
                    ---------------------------------
                    TOTAL: = 16 bytes


                    =============== =============== =============== ============


                    small question: virutal functions, regular fucntions and inline
                    functions take the same space (ex: 4 bytes or 8 bytes 32 and 64 bits
                    respectively)? According to alignement rules: compiler is tring to fit
                    as many variable (data types) as possible in each block for as long as
                    it fits entirely or else adds padding... is that the correct way of
                    thinking?


                    Thanks...


                    ...Puzzlecracke r!

                    Comment

                    • puzzlecracker

                      #11
                      Re: size of memory in C -- allocation

                      Let me know if i solved your examples right, on 32 and 64 bit machine.
                      If not, please explain where I made a mistake.[color=blue]
                      >The exercise of a 64-bit machine is left to the
                      >reader. Hint: a 64-bit machine likes to fetch
                      >at every 8 bytes; and assume a short int is either
                      >16 or 32 bits.[/color]
                      since short int is 2 bytes and int is 4 bytes, it will occupy a block
                      of 8 byte, so the total size is 8 byte.
                      2)[color=blue]
                      >struct A
                      >{
                      > char c;
                      >short int si;
                      > int j;
                      > char d
                      > int i;
                      >};[/color]
                      32 bit machine:
                      -----------------
                      1st block: s, si +padding = 4 bytes
                      2nd block: j = 4 bytes
                      3rd block: d+padding = 4 bytes
                      4th block: i = 4 bytes
                      -----------------------------------
                      TOTAL: = 16 bytes
                      64 bit Machine
                      ----------------
                      1st block: s,si j+d = 8byte
                      2nd block i+padding = 8byte
                      ------------------------------
                      TOTAL: 16 bytes
                      2)[color=blue]
                      >struct B
                      >{
                      > int i;
                      > short int si;
                      > char c;
                      > char d;
                      > int j;
                      >};[/color]
                      32 bit machine
                      --------------
                      1st block: i = 4 bytes
                      2rd block: s1, c d = 4 bytes
                      4th block j = 4 bytes
                      -----------------------------------
                      TOTAL: 12 bytes
                      64 bit Machine
                      ----------------
                      1st block: i, si c + d = 8 byte
                      2nd block j = 8 byte
                      ---------------------------------
                      TOTAL: = 16 bytes
                      =============== =============== =============== ============
                      Small question: virutal functions, regular fucntions and inline
                      functions take the same space (ex: 4 bytes or 8 bytes 32 and 64 bits
                      respectively)? According to alignement rules: compiler is tring to fit
                      as many variable (data types) as possible in each block for as long as
                      it fits entirely or else adds padding... is that the correct way of
                      thinking?

                      Is function in the struct saved as pointer and takes on its size?
                      Thanks...
                      ....Puzzlecrack er

                      Comment

                      • puzzlecracker

                        #12
                        Re: size of memory in C -- allocation


                        Please let me know if I solved these ones correctly. thx
                        [color=blue]
                        >struct A
                        >{
                        > char c;
                        >short int si;
                        > int j;
                        > char d
                        > int i;
                        >};[/color]


                        32 bit machine:
                        -----------------
                        1st block: s, si +padding = 4 bytes
                        2nd block: j = 4 bytes
                        3rd block: d+padding = 4 bytes
                        4th block: i = 4 bytes
                        -----------------------------------
                        TOTAL: = 16 bytes

                        64 bit Machine
                        ----------------
                        1st block: s,si j+d = 8byte
                        2nd block i+padding = 8byte
                        ------------------------------
                        TOTAL: 16 bytes


                        2)


                        [color=blue]
                        >struct B
                        >{
                        > int i;
                        > short int si;
                        > char c;
                        > char d;
                        > int j;
                        >};[/color]


                        32 bit machine
                        --------------
                        1st block: i = 4 bytes
                        2rd block: s1, c d = 4 bytes
                        4th block j = 4 bytes
                        -----------------------------------
                        TOTAL: 12 bytes

                        64 bit Machine
                        ----------------
                        1st block: i, si c + d = 8 byte
                        2nd block j = 8 byte
                        ---------------------------------
                        TOTAL: = 16 bytes


                        =============== =============== =============== ============


                        small question: virutal functions, regular fucntions and inline
                        functions take the same space (ex: 4 bytes or 8 bytes 32 and 64 bits
                        respectively)? According to alignement rules: compiler is tring to fit
                        as many variable (data types) as possible in each block for as long as
                        it fits entirely or else adds padding... is that the correct way of
                        thinking?


                        Thanks...


                        ...Puzzlecracke r!

                        Comment

                        • Keith Thompson

                          #13
                          Re: size of memory in C -- allocation

                          "puzzlecrac ker" <ironsel2000@gm ail.com> writes:[color=blue]
                          > Let me know if i solved your examples right, on 32 and 64 bit machine.
                          > If not, please explain where I made a mistake.
                          >[color=green]
                          >>The exercise of a 64-bit machine is left to the
                          >>reader. Hint: a 64-bit machine likes to fetch
                          >>at every 8 bytes; and assume a short int is either
                          >>16 or 32 bits.[/color]
                          >
                          > since short int is 2 bytes and int is 4 bytes, it will occupy a block
                          > of 8 byte, so the total size is 8 byte.[/color]

                          How do you know that short it is 2 bytes and int is 4 bytes? That's
                          not necessarily true for all implementations , even for all
                          implementations on 32-bit machines (whatever "32-bit machines" might
                          mean).

                          And even if you happen to know that short int is 2 bytes and int is 4
                          bytes on a given implementation, that still doesn't tell you the size
                          of a structure. Alignment requirements vary from one system to
                          another, and implementations vary in how they respond to those
                          requirements.

                          A compiler may insert padding between any two struct members and/or
                          after the last member. The standard says nothing about when it can do
                          this, or how much padding it will insert.

                          --
                          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                          We must do something. This is something. Therefore, we must do this.

                          Comment

                          • Keith Thompson

                            #14
                            Re: size of memory in C -- allocation

                            "puzzlecrac ker" <ironsel2000@gm ail.com> writes:[color=blue][color=green]
                            >> The "virtual" is a syntax error. Again the struct is missing a
                            >> label, and the answer to a applies.[/color]
                            >
                            > Ok, let's refer to C++ struct - yes this is topic off, but I didn't get
                            > sufficient anwer in different group and this group seem to be most
                            > valuable given that the question is somewhat related.[/color]

                            Let's not. We don't discuss C++ here; that's what comp.lang.c++ is
                            for. (And if you don't like the answers you get there, that doesn't
                            make your question topical here.)

                            We tend to be more strict here about topicality that most newsgroups.

                            See <http://www.ungerhu.com/jxh/clc.welcome.txt >.

                            --
                            Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                            San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                            We must do something. This is something. Therefore, we must do this.

                            Comment

                            • Jack Klein

                              #15
                              Re: size of memory in C -- allocation

                              On 18 Jan 2005 12:40:16 -0800, "puzzlecrac ker" <ironsel2000@gm ail.com>
                              wrote in comp.lang.c:
                              [color=blue]
                              > Let me know if i solved your examples right, on 32 and 64 bit machine.
                              > If not, please explain where I made a mistake.[/color]

                              How many times do you need to be told:

                              1. This is not a language question. The C language doesn't know or
                              care how many bits a machine has, and leaves all of these issues up to
                              the specific compiler to define?

                              2. That there is no general answer even possible, because there are
                              more than one 32-bit processor and more than one 64-bit processor, and
                              they have differences.
                              [color=blue][color=green]
                              > >The exercise of a 64-bit machine is left to the
                              > >reader. Hint: a 64-bit machine likes to fetch
                              > >at every 8 bytes; and assume a short int is either
                              > >16 or 32 bits.[/color]
                              >
                              > since short int is 2 bytes and int is 4 bytes, it will occupy a block
                              > of 8 byte, so the total size is 8 byte.[/color]

                              I worked today with a compiler where short is 1 byte, int is 1 byte,
                              and long is 2 bytes. I have worked in the past with compilers where
                              char, short, int, and long are all 1 byte. Even that is not specified
                              by the C standard and varies with processor and compiler.

                              So go away.

                              --
                              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

                              Working...