Re: size of array??

Discussion in 'C Programming' started by Alan Gillespie, Jul 9, 2003.

  1. > sizeof will give you the number of bytes taken by the pointer.
    > Generally this will be 4 bytes, since it is the address...
    > like 0xFeB78902.


    Not strictly true. The sizeof operator gives its operand's size in units of
    chars, not bytes - hence by definition sizeof(char) is 1, whether or not a
    char occupies one byte.

    The actual size of a char is left as an implementation detail, although
    virtually all compilers will use one byte.

    However we don't talk about implementations here; just the standard :eek:)
     
    Alan Gillespie, Jul 9, 2003
    #1
    1. Advertising

  2. > In the sence of C a char is a byte and a byte is a char by defintion.
    > The two are actually the same, so one can even say tha sizeof(char) is
    > not only defined to be 1, but is defined to be exactly one byte.


    Standard C has no notion of a byte. A particular implementation might have,
    or a programmer might choose to define it. The standard defines a char by
    what it is expected to hold - a character in the target character set - and
    not by its size.

    >
    > >
    > > The actual size of a char is left as an implementation detail, although
    > > virtually all compilers will use one byte.
    > >
    > > However we don't talk about implementations here; just the standard :eek:)

    >
    > It happens to be the case that the meaning of byte in the non-C world is
    > eight Bits, but in C bytes can have more (not less) than 8 Bits.


    Of course you are free to define a type called "byte" in your code, and make
    it any size you like. That is your prerogative, but I hope I never have to
    review any of your code.
     
    Alan Gillespie, Jul 9, 2003
    #2
    1. Advertising

  3. Alan Gillespie

    Richard Bos Guest

    "Alan Gillespie" <> wrote:

    > > In the sence of C a char is a byte and a byte is a char by defintion.
    > > The two are actually the same, so one can even say tha sizeof(char) is
    > > not only defined to be 1, but is defined to be exactly one byte.

    >
    > Standard C has no notion of a byte.


    From n869:

    3.4
    [#1] byte
    addressable unit of data storage large enough to hold any
    member of the basic character set of the execution
    environment

    [#2] NOTE 1 It is possible to express the address of each
    individual byte of an object uniquely.

    [#3] NOTE 2 A byte is composed of a contiguous sequence of
    bits, the number of which is implementation-defined. The
    least significant bit is called the low-order bit; the most
    significant bit is called the high-order bit.

    'nuff said.

    Richard
     
    Richard Bos, Jul 9, 2003
    #3
  4. On Wed, 9 Jul 2003 13:16:39 +0100,
    Alan Gillespie <> wrote:
    >> In the sence of C a char is a byte and a byte is a char by defintion.
    >> The two are actually the same, so one can even say tha sizeof(char) is
    >> not only defined to be 1, but is defined to be exactly one byte.

    >
    > Standard C has no notion of a byte.


    ISO/IEC 9899:1999

    3.6
    1 byte
    addressable unit of data storage large enough to hold any member of the
    basic character set of the execution environment

    The word byte is all over the standard (some 60 times).

    > A particular implementation might have,
    > or a programmer might choose to define it. The standard defines a char by
    > what it is expected to hold - a character in the target character set - and
    > not by its size.


    char is a type, and byte is not, therefore they are not entirely the
    same thing. However, sizeof(char) is always 1, and is defined as the
    smallest possible addressable unit. The sizof operator yields the size
    of its operand in _bytes_. Therefore, a byte and a char in C always are
    of exactly the same size. For all practical uses and intents, you can
    safely regard a byte and a char as more or less the same thing, in C.

    >> >
    >> > The actual size of a char is left as an implementation detail, although
    >> > virtually all compilers will use one byte.
    >> >
    >> > However we don't talk about implementations here; just the standard :eek:)

    >>
    >> It happens to be the case that the meaning of byte in the non-C world is
    >> eight Bits, but in C bytes can have more (not less) than 8 Bits.

    >
    > Of course you are free to define a type called "byte" in your code, and make
    > it any size you like. That is your prerogative, but I hope I never have to
    > review any of your code.


    Hmmm... I wonder about the general quality of your code reviews now.

    Martien
    --
    |
    Martien Verbruggen | Blessed are the Fundamentalists, for they
    | shall inhibit the earth.
    |
     
    Martien Verbruggen, Jul 9, 2003
    #4
  5. On Wed, 09 Jul 2003 12:35:51 GMT, in comp.lang.c ,
    (Richard Bos) wrote:

    >"Alan Gillespie" <> wrote:
    >
    >> > In the sence of C a char is a byte and a byte is a char by defintion.
    >> > The two are actually the same, so one can even say tha sizeof(char) is
    >> > not only defined to be 1, but is defined to be exactly one byte.

    >>
    >> Standard C has no notion of a byte.

    >
    >From n869:
    >
    > 3.4 [#1] byte


    I think Alan's point tho was that there is no C type "byte", and no
    function returns bytes or takes bytes as a parameter, so its incorrect
    to refer to sizeof as telling you the size in bytes.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Mark McIntyre, Jul 9, 2003
    #5
  6. Alan Gillespie

    pete Guest

    Mark McIntyre wrote:
    >
    > On Wed, 09 Jul 2003 12:35:51 GMT, in comp.lang.c ,
    > (Richard Bos) wrote:
    >
    > >"Alan Gillespie" <> wrote:
    > >
    > >> > In the sence of C a char is a byte
    > >> > and a byte is a char by defintion.
    > >> > The two are actually the same, so one can
    > >> > even say tha sizeof(char) is
    > >> > not only defined to be 1, but is defined to be exactly one byte.
    > >>
    > >> Standard C has no notion of a byte.

    > >
    > >From n869:
    > >
    > > 3.4 [#1] byte

    >
    > I think Alan's point tho was that there is no C type "byte", and no
    > function returns bytes or takes bytes as a parameter, so its incorrect
    > to refer to sizeof as telling you the size in bytes.


    That point, would be wrong.
    sizeof isn't a function.
    The return type of sizeof is size_t, and it counts bytes.

    N869
    6.5.3.4 The sizeof operator
    Semantics
    [#2] The sizeof operator yields the size (in bytes)
    ^^^^^^^^
    of its operand, which may be an expression
    or the parenthesized name of a type.
     
    pete, Jul 9, 2003
    #6
  7. Alan Gillespie

    Richard Bos Guest

    Mark McIntyre <> wrote:

    > On Wed, 09 Jul 2003 12:35:51 GMT, in comp.lang.c ,
    > (Richard Bos) wrote:
    >
    > >"Alan Gillespie" <> wrote:
    > >
    > >> > In the sence of C a char is a byte and a byte is a char by defintion.
    > >> > The two are actually the same, so one can even say tha sizeof(char) is
    > >> > not only defined to be 1, but is defined to be exactly one byte.
    > >>
    > >> Standard C has no notion of a byte.

    > >
    > >From n869:
    > >
    > > 3.4 [#1] byte

    >
    > I think Alan's point tho was that there is no C type "byte", and no
    > function returns bytes or takes bytes as a parameter, so its incorrect
    > to refer to sizeof as telling you the size in bytes.


    *sigh*

    3.5
    [#1] character
    bit representation that fits in a byte

    That help?

    Richard
     
    Richard Bos, Jul 9, 2003
    #7
  8. On Wed, 09 Jul 2003 14:02:02 GMT, in comp.lang.c ,
    (Richard Bos) wrote:

    >Mark McIntyre <> wrote:
    >
    >> I think Alan's point tho was that there is no C type "byte", and no
    >> function returns bytes or takes bytes as a parameter, so its incorrect
    >> to refer to sizeof as telling you the size in bytes.

    >
    > 3.5
    > [#1] character
    > bit representation that fits in a byte
    >
    >That help?


    Help with what? There's still no C type "byte"/

    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Mark McIntyre, Jul 9, 2003
    #8
  9. On Wed, 09 Jul 2003 09:28:41 -0400, in comp.lang.c , pete
    <> wrote:

    >Mark McIntyre wrote:


    >> I think Alan's point tho was that there is no C type "byte", and no
    >> function returns bytes or takes bytes as a parameter, so its incorrect
    >> to refer to sizeof as telling you the size in bytes.


    (gah, need to read more carefully... )


    >That point, would be wrong.
    >sizeof isn't a function.


    irrelevant .

    >The return type of sizeof is size_t, and it counts bytes.


    Quite correct, my error. However sizeof not "return" bytes, it returns
    a size_t. There's still no C type "byte".


    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Mark McIntyre, Jul 9, 2003
    #9
  10. Alan Gillespie

    Micah Cowan Guest

    "Alan Gillespie" <> writes:

    > > sizeof will give you the number of bytes taken by the pointer.
    > > Generally this will be 4 bytes, since it is the address...
    > > like 0xFeB78902.

    >
    > Not strictly true. The sizeof operator gives its operand's size in units of
    > chars


    Please stop spreading this misinformation. Or have you had a chance to
    read the corrections to your similar assertions from before.

    > , not bytes - hence by definition sizeof(char) is 1, whether or not a
    > char occupies one byte.


    This is absolutely untrue. Before you start making assertions about
    how the standard defines something, I suggest you actually read it.

    § 6.5.3.4#2:

    The sizeof operator yields the size (in bytes) of its operand...

    § 3.6 (definition of a byte):

    addressable unit of data storage large enough to hold any member of
    the basic character set of the execution environment.

    § 6.2.5#3

    An object declared as type char is large enough to store any member
    of the basic execution character set.

    § 6.5.3.4#3:

    When applied to an operand that has type char, unsigned
    char,orsigned char, (or a qualified version thereof) the result is
    1.

    -Micah
     
    Micah Cowan, Jul 10, 2003
    #10
  11. Alan Gillespie

    pete Guest

    Mark McIntyre wrote:
    >
    > On Wed, 09 Jul 2003 09:28:41 -0400, in comp.lang.c , pete
    > <> wrote:
    >
    > >Mark McIntyre wrote:

    >
    > >> I think Alan's point tho was that there is no C type "byte", and no
    > >> function returns bytes or takes bytes as a parameter,
    > >> so its incorrect
    > >> to refer to sizeof as telling you the size in bytes.

    >
    > (gah, need to read more carefully... )
    >
    > >That point, would be wrong.
    > >sizeof isn't a function.

    >
    > irrelevant .


    That's MY point.
    You provided a reason that has something
    to do with functions and types.
    Functions and types are irrelavant as to whether or not
    the value yielded by sizeof, represents bytes.

    > >The return type of sizeof is size_t, and it counts bytes.

    >
    > Quite correct, my error.
    > However sizeof not "return" bytes, it returns
    > a size_t.


    That's what I just said.
    What's the "However" for ?

    > There's still no C type "byte".


    What does the fact that there is no type "byte"
    have to do with whether or not sizeof yields
    the size of a type in bytes ?

    Are you still stuck in that frame of mind where you think
    that everything that isn't a type, isn't defined in C?

    http://groups.google.com/groups?hl=...274&seekm=#link25

    --
    pete
     
    pete, Jul 10, 2003
    #11
  12. Alan Gillespie

    Richard Bos Guest

    Mark McIntyre <> wrote:

    > On Wed, 09 Jul 2003 14:02:02 GMT, in comp.lang.c ,
    > (Richard Bos) wrote:
    >
    > >Mark McIntyre <> wrote:
    > >
    > >> I think Alan's point tho was that there is no C type "byte", and no
    > >> function returns bytes or takes bytes as a parameter, so its incorrect
    > >> to refer to sizeof as telling you the size in bytes.

    > >
    > > 3.5
    > > [#1] character
    > > bit representation that fits in a byte
    > >
    > >That help?

    >
    > Help with what? There's still no C type "byte"/


    So? A char is one byte large, guaranteed by the Standard. A byte is the
    size of one char, guaranteed by the Standard. Whether sizeof determines
    size in number of chars or in bytes is undecidable, since the two are
    exactly the same within the C Standard.

    Your complaint is like that of someone who wants volumes reported in
    cubic decimetres rather than in litres.

    Richard
     
    Richard Bos, Jul 10, 2003
    #12
  13. On Wed, 09 Jul 2003 23:49:16 -0400, in comp.lang.c , pete
    <> wrote:

    >Mark McIntyre wrote:
    >>
    >>
    >> irrelevant .

    >
    >That's MY point.
    >You provided a reason that has something
    >to do with functions and types.


    no, you misunderstood my reason.

    >Functions and types are irrelavant as to whether or not
    >the value yielded by sizeof, represents bytes.


    Sure, but its also irrelevant that sizeof is a unary operator not a
    function.

    >> >The return type of sizeof


    as /you/ pointed out, its an operator, not a function :) )

    >> > is size_t, and it counts bytes.

    >>
    >> Quite correct, my error.
    >> However sizeof not "return" bytes, it returns
    >> a size_t.

    >
    >That's what I just said. What's the "However" for ?


    because my original post said "there's no C function that returns the
    type byte", (please extend that to operators too, as was my intent)

    >> There's still no C type "byte".

    >
    >What does the fact that there is no type "byte"


    the original point being made was that there is no byte type in C.

    >have to do with whether or not sizeof yields
    >the size of a type in bytes ?


    nothing, thats a different point.

    >Are you still stuck in that frame of mind where you think
    >that everything that isn't a type, isn't defined in C?


    I've never been in that frame of mind. What on earth makes you think
    this?

    (snip link to google groups)

    not sure what you're trying to do by posting this link which seems
    spectacularly irrelevant to this thread .BTW since I don't read
    anything by Dan Pop, its pretty uninteresting to me anyway.



    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Mark McIntyre, Jul 10, 2003
    #13
  14. On Thu, 10 Jul 2003 08:08:40 GMT, in comp.lang.c ,
    (Richard Bos) wrote:

    >Mark McIntyre <> wrote:
    >
    >> Help with what? There's still no C type "byte"/

    >
    >So?


    and? :)

    >Your complaint is like that of someone who wants volumes reported in
    >cubic decimetres rather than in litres.


    ?Que?
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Mark McIntyre, Jul 10, 2003
    #14
  15. Alan Gillespie

    Richard Bos Guest

    Mark McIntyre <> wrote:

    > On Thu, 10 Jul 2003 08:08:40 GMT, in comp.lang.c ,
    > (Richard Bos) wrote:
    >
    > >Your complaint is like that of someone who wants volumes reported in
    > >cubic decimetres rather than in litres.

    >
    > ?Que?


    Same difference.

    Richard
     
    Richard Bos, Jul 10, 2003
    #15
  16. On Thu, 10 Jul 2003 11:11:22 GMT, in comp.lang.c ,
    (Richard Bos) wrote:

    >Mark McIntyre <> wrote:
    >
    >> On Thu, 10 Jul 2003 08:08:40 GMT, in comp.lang.c ,
    >> (Richard Bos) wrote:
    >>
    >> >Your complaint is like that of someone who wants volumes reported in
    >> >cubic decimetres rather than in litres.

    >>
    >> ?Que?

    >
    >Same difference.


    I don't think we have an argument here. I was simply trying to point
    out that there's no type "byte" in C, and no function (or operator)
    can therefore return a byte, or even a pointer to one.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Mark McIntyre, Jul 10, 2003
    #16
  17. On Thu, 10 Jul 2003 07:50:32 -0400, in comp.lang.c , pete
    <> wrote:

    >
    >> BTW since I don't read anything by Dan Pop,
    >> its pretty uninteresting to me anyway.

    >
    >Dan Pop and Ben Pfaff are two different people.


    I'm aware of that. I'm not sure why its relevant tho.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Mark McIntyre, Jul 10, 2003
    #17
  18. Alan Gillespie

    pete Guest

    pete, Jul 10, 2003
    #18
  19. [OT: Google snipping] Re: size of array??

    On Thu, 10 Jul 2003, pete wrote:
    >
    > Arthur J. O'Dwyer wrote:
    >
    > > P.S to pete: Try to snip Google Groups URLs to a reasonable length.
    > > http://groups.google.com/groups?
    > > threadm=87n0tjaugc.fsf%40pfaff.Stanford.EDU&rnum=1
    > > would have been enough, and wouldn't have wrapped twice on my screen.


    Until someone put it in >>quotes, of course. ;-)

    > That's a good idea, but I don't know how to get that URL, from this:
    >
    > http://groups.google.com/groups?
    > hl=en&lr=&ie=UTF-8&frame=right&


    First pass: Strip all this. The default language is English, and the
    default encoding is UTF-8 (AFAIK), and whatever lr= is, it never gets
    used.

    > rnum=21&thl=1206107469,1206037441,1206000908,1205997268,1205804151,
    > 1205793896,1205336111,1205220087,1205150173,1205606600,1205985361,
    > 1205548274&


    I don't know what these numbers refer to, but your first goal should be
    to find a URL for the page that doesn't contain them. They don't look
    very informative (in the information-theoretical sense :).

    > seekm=3D1A95D9.1707%40mindspring.com#link25


    The only important bit: the message-ID.

    With a bit of practice, I've gotten to where I can snip Google URLs
    by directly editing the address line in IE. But I've never seen one
    like yours, with all those numbers in it. So to get from (A) to
    (B) much more directly, one can:

    Go to the original URL.
    Click "View this article only."
    Click "Complete Thread (nnn articles)."
    Cut and paste the new URL from the address bar
    (or "Copy Shortcut" or whatever on the last click).

    Strip the hl, dq, lr, ie, and prev attributes from the URL.
    Strip the rnum attribute too, if it's 1.
    Test the stripped URL to make sure you didn't break it.

    HTH,
    -Arthur
     
    Arthur J. O'Dwyer, Jul 10, 2003
    #19
  20. Alan Gillespie

    Micah Cowan Guest

    Mark McIntyre <> writes:

    > On Thu, 10 Jul 2003 07:50:32 -0400, in comp.lang.c , pete
    > <> wrote:
    >
    > >Mark McIntyre wrote:
    > >>
    > >> the original point being made was that there is no byte type in C.

    > >
    > >That's not the original point.
    > >That's something you just introduced two posts up this thread

    >
    > thats correct, my original point was that there's no byte type. Do you
    > have a problem with that?


    The original point was not yours in the first place. You changed it
    into something else, which no one was arguing in the first place. You
    *conjectured* that it was what was meant by Alan Gillespie upthread,
    but it isn't: he literally meant that the C standard has no concept of
    a byte (which obviously means he hasn't *read* the thing). He has made
    this absurd claim several times, and been corrected several times. I
    am under the impression that he doesn't read follow-ups to his own
    messages (personally, I always read follow-ups to my thread first, in
    case I wouldn't have time to read everything, which is frequently so),
    so I have written him an e-mail imploring him to stop posting
    assertions about a document which he clearly has not read.

    -Micah
     
    Micah Cowan, Jul 11, 2003
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zygmunt Krynicki
    Replies:
    1
    Views:
    644
    Ivan Vecerina
    Oct 11, 2003
  2. Denis Palas
    Replies:
    2
    Views:
    729
    Daniel Pitts
    Dec 19, 2006
  3. Replies:
    5
    Views:
    585
    Flash Gordon
    Apr 9, 2006
  4. Replies:
    8
    Views:
    531
    Bob Hairgrove
    Apr 10, 2006
  5. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,743
    Michael Jung
    May 25, 2008
Loading...

Share This Page