Les wrote:
On Thu, 2007-05-24 at 17:07 -0500, Mike McCarty wrote:
[snip]
I suspect you are conflating "signed char" with "a character in the
execution environment which, when its code is stored into a signed char,
results in a negative value."
Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
Hi, Mike,
when you passed the char to the printf using %d, it was promoted to
an int which is signed. That promotion will automatically extend the
MSB, which in this case was a one (-1 decimal as a char is 0xff, and
extended is 0xffffffff expressed as an int, which prints as -1.
No, it does not automatically extend in the way you state.
$ cat uchar.c
#include <stdio.h>
int main(void) {
unsigned char Chr;
Chr = -1;
printf("%d\n",Chr);
return 0;
}
$ gcc -o uchar uchar.c
$ ./uchar
255
Just as I stated, you seem to be conflating the concept of
values and signedness of the type.
Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!