This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

No error when converting unsigned char to pointer?

I just noticed that my Keil C compiler
doesn't flag assignment of an unsigned char
to a pointer as an error:

unsigned char xdata *src;
unsigned char xdata array[10];

src = array[0];
This doesn't seem to generate any compile
warning, even though what I should have done
is

src = &array[0];

Is this some known bug?

Parents
  • "Is this some known bug?"

    Nope.
    What you have written is perfectly valid 'C' syntax - so the compiler has nothing to complain about.

    The fact that you can do this in 'C' is, of course, both a blessing and a curse: a blessing as the compiler won't get in your way if you have a valid reason to do it; and a curse if you do it by accident - like here!

    As I've said before, "big" compilers like UNIX native ones, MSVC, Borland, etc tend to give you far more in the way of diagnostics than the "small" embedded cross-compilers like Keil. Such "big" compilers may well give you a "suspicious pointer conversion" warning, or similar; but in the embedded world, it's more likely that you do want to do "dirty tricks" like this...

    Therefore, as I've also said before, it is worth writing your code in such a way that a "big" compiler will also accept it - and give you all those extra warnings (you can download the Borland Compiler for free).

    Alternatively, use a static-analysis tool like lint

    See http://www.keil.com/forum/docs/thread1680.asp

Reply
  • "Is this some known bug?"

    Nope.
    What you have written is perfectly valid 'C' syntax - so the compiler has nothing to complain about.

    The fact that you can do this in 'C' is, of course, both a blessing and a curse: a blessing as the compiler won't get in your way if you have a valid reason to do it; and a curse if you do it by accident - like here!

    As I've said before, "big" compilers like UNIX native ones, MSVC, Borland, etc tend to give you far more in the way of diagnostics than the "small" embedded cross-compilers like Keil. Such "big" compilers may well give you a "suspicious pointer conversion" warning, or similar; but in the embedded world, it's more likely that you do want to do "dirty tricks" like this...

    Therefore, as I've also said before, it is worth writing your code in such a way that a "big" compiler will also accept it - and give you all those extra warnings (you can download the Borland Compiler for free).

    Alternatively, use a static-analysis tool like lint

    See http://www.keil.com/forum/docs/thread1680.asp

Children
No data