typecast

To the best of my knowledge the 'if' below should test 2 bytes.

What is wrong here

void funct(unsigned char *valptr)
{
  if (((unsigned int)*valptr) != 0)

generates

0012 8F82          MOV     DPL,R7
0014 8E83          MOV     DPH,R6
0016 E0            MOVX    A,@DPTR
0017 60F9          JZ      ?C0047

also

  *valptr = (unsigned long) 0 ;

generates one byte of zero only

Is this Keil "exceptions" or am I doing something wrong

Thanx,

Erik


Parents
  • "The generated code is perfectly correct. In the first example, the condition is true if (*valptr) is nonzero, whether you convert it to unsigned int or not"

    If valptr point to an int, how can !=0 be true if ONE BYTE is (non)zero. If the first byte is zero ond the second byte of the int is non-zero, the test should fail. The second half of the int is never tested. (the snippet is complete - only one byte is tested)

    Re the second example:
    How can STORING a long be accomplished by storing a byte.

    Erik

    Erik

Reply
  • "The generated code is perfectly correct. In the first example, the condition is true if (*valptr) is nonzero, whether you convert it to unsigned int or not"

    If valptr point to an int, how can !=0 be true if ONE BYTE is (non)zero. If the first byte is zero ond the second byte of the int is non-zero, the test should fail. The second half of the int is never tested. (the snippet is complete - only one byte is tested)

    Re the second example:
    How can STORING a long be accomplished by storing a byte.

    Erik

    Erik

Children
More questions in this forum