Wilson Yeung wrote:
c++ *guaranties* that char is always one byte. It cannot be anything
else. The difference is that from c++ point of view byte is not limited
to 8 bits (it could be more, but not less). Not sure about c, but I
expect it be the same


The definition of a byte as 8 bits is not likely to change in the next
20 years.  Once again, too much code would break.  Can you find one
example in the last 15 years of a byte which is not an octet?

Byte is always 8 bits :)
just because you are programming for windows and/or for intell processor doesn't mean that there are no other architecures out there. Why so strange number 15 yrs? do you think that all that non 8-bit bytes were on ancient mainframes or what?? I'm not going to look for examples, just read c++ faq, if you haven't read so far...
http://www.parashift.com/c++-faq-lite/intrinsic-types.html



Why would you think that sizeof(int) is 4?? It's only happens to be so
on your machine/compiler. It only says that sizeof(int) is at least 2
bytes. Sizeof(long) at least 4... (AFAIK)


I don't think this.  Like I said, "no one promises that sizeof(int) ==
4". But it is on 32 bit machines and it is on 64 bit machines too. And it won't be changing any time soon. If you can give me a real
example of a 32 bit or 64 bit platform where sizeof(int) != 4, I would
be very surprised.

World is not limited to 32 & 64 bit. (and I don't mean that sizeof(int) != 4 for only 16-bit machines) What about some specialized hardware, satelites etc... they may have something different. And this is not realated to 32 & 64 bit at all. This is compiler dependent.


I am aware of what the standard guarantees, and also aware of what's
true in practice.  The best one can do is introduce some typedefs,
like what's in usr/include/stdint.h, but at the end of the day, you're
depending on an int to be 32 bits.

You'd be safer to depend on long int, which is at least 4 bytes.


Compiler vendors like gcc have defined sizeof(void) == 1, and pointer
arithmetic on a void * is defined thusly.

Maybe it's defined as 1 byte, but what I care is that it doesn't make sense to me to do arithmetics with void pointers. That's it

Reply via email to