Re: how to print it out



Jack Klein <jackklein@xxxxxxxxxxx> writes:
On Tue, 21 Feb 2006 05:00:19 +0200, "stathis gotsis"
<stathisgotsis@xxxxxxxxxxx> wrote in comp.lang.c:
[...]
Is char restricted to 8 bits? If not, maybe this is more general:

No, char is not restricted to 8 bits, it can't be less buy may be
more. I routinely work on C implementations for DSPs where chars have
16 or 32 bits. The macro CHAR_BIT in <limits.h> gives the number of
bits.

#define nyb_u(a) (((a)>>(sizeof(a)*8-4))&0x0F)

Uh, no, while char is not limited to 8 bits, it is limited to being
exactly one byte. sizeof(char) is 1 by definition in C, always has
been, always will be. Even if char contains more than one octet,
which is the proper term for a collection of exactly 8 bits.

So your expression is exactly equivalent to Rod's.

Except that character constants are of type int, so nyb_u('x') will
use sizeof('x'), which is the same as sizeof(int). You probably
don't want to apply sizeof to the argument.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <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.
.



Relevant Pages

  • Re: Type conversion
    ... Jack Klein writes: ... guaranteed representable even in 'signed char'. ... When converting a higher ... rank integer type to a lesser rank signed integer type, ...
    (comp.lang.c)
  • Re: C standard question?
    ... Keith Thompson and Jack Klein have so far used the word "ridiculous". ... was surprised to discover that "char unsigned" ... equivalent, assuming a non-buggy compiler. ... int main ...
    (comp.lang.c)
  • Re: signed char and unsigned char difference
    ... "Jack Klein" wrote... ... Unless plain char is signed, there's no requirement that the value of 'a' ... This is ambiguous since a literal 'a' is already of int and no promotion ...
    (comp.lang.c)
  • Re: sizeof(int)
    ... Jack Klein wrote: ... which is indeed the smallest addressable storage unit. ... You can only store one char per byte, ...
    (comp.lang.cpp)
  • Re: How to print out
    ... Jack Klein wrote: ... Which four of the 32 bits in the char are "lower" and which are ... And why are you posting this again instead of reading the replies to ... FAQs for ...
    (comp.lang.c)