Mail Archives: djgpp/2000/01/26/10:27:06
On Tue, 25 Jan 2000, Petr Maxa wrote:
> int main()
> {
> uchar buf[256];
>
> code_message(buf,0x81,(uchar *)"Hello world\n",13); /* 1-st overtyping */
>
> if((buf[0]==0xff) && (buf[1]==0x81)) /*!! if we use signed char, this
> comparation would be useless !! */
> printf((char*)buf+3); /* 2-nd overtyping */
> return 0;
> }
I was referring to the last cast, inside `printf': why did you need
it? AFAIK, "printf(buf+3)" should work with no problems. Doesn't it?
> 2. printf function request the "signed char *" type as the first parameter.
AFAIK, printf can do well with unsigned char as well.
> For curiosity (or off topic), there is also another problem. If You have
> signed char type variable with value 0xff (-1) and You convert it to int,
> You get 0xffffffff that is also -1, but in our case it might produce buggy
> code.
Your code mixes signed and unsigned integral types. This always
spells trouble. You should avoid mixing signed and unsigned types at
all costs.
- Raw text -