Re: Quick check on signed promotion of bytes



On Jan 31, 6:22 pm, Eric Sosman <Eric.Sos...@xxxxxxx> wrote:
t...@xxxxxxxxxxx wrote:
I have a byte called "x". I want byte "y" to be the complement of
"x" (i.e. all the bits flipped).

Initially I wrote:

char unsigned x, y;

...

x = 72;

y = ~x;

But then I thought that the following might happen on your average
system (CHAR_BIT == 8, sizeof(int) == 4):

1) x is promoted to signed int.
2) The complement is take of this signed int.
3) This signed int is then converted to an unsigned char

That's right, under your assumptions. On "exotic" machines
where UCHAR_MAX > INT_MAX (for example, on hardware where all
of char, short, and int are 16 bits wide), then x promotes to
an unsigned int instead of to an int in step 1.

Also see vippstar's response: It's wrong.
Ah, I apologise, just something i am not sure about, char unsigned x,
y; means unsigned char x, 'plain' char y?
.



Relevant Pages

  • Putty key format.
    ... /* Hacked up ssh-add.c code to convert an OpenSSH key into a format ... static char *comment = NULL; ... int length; ... static unsigned char * buffer = NULL; ...
    (comp.security.ssh)
  • [EXPL] KSTAT (and Maybe Others) Bypass (Phantasmagoria)
    ... void cleanup_module{ ... char computed_address; ... int isNotOp; ... unsigned char backuped; ...
    (Securiteam)
  • Re: memory leak?
    ... char, short, int are all 16 bits. ... them rely on EOF being returned by the function. ... value distinct from all unsigned char values. ...
    (microsoft.public.vc.mfc)
  • Re: Works on Windows but not on HPUX, Help Please
    ... do I read C89 correctly that the char strwill be ... converted to an int, not an unsigned int, even if char is unsigned, ... unsigned short can also be promoted to signed int. ... if char is unsigned then there is undefined behaviour ...
    (comp.lang.c)
  • driver for thinkpad fingerprint sensor
    ... Fingerprint scanner driver for thinkpad x60. ... udf_crc(u8 *data, unsigned int size, u16 crc) ... void printhex(unsigned char *data, int len) ... unsigned char inbuf; ...
    (Linux-Kernel)