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

get compiler warning if unsigned variable is assigned with a signed value

Can I get a compiler warning if I accidentaly
assign a signed int to an unsigned int variable ?

eg:
unsigned int ui_par = 0 ; signed int si_par = -1 ;

Normally I would write something like:
ui_par = (WORD) (MAX(0,si_par)) ;

But if I accidentally do the following:
ui_par = si_par ;
=> ui_par = 65535
=> no compiler warning ?

Parents
  • 'C' is not a strongly-typed language, so compilers can't be relied upon to catch such mistakes - as they are not "errors" as far as the language is concerned.

    Some compilers might give a warning, though.
    You'll have to check in the appropriate Manual.

    You should use something like LINT to detect such mistakes, and/or use a strongly-typed language like Pascal...

Reply
  • 'C' is not a strongly-typed language, so compilers can't be relied upon to catch such mistakes - as they are not "errors" as far as the language is concerned.

    Some compilers might give a warning, though.
    You'll have to check in the appropriate Manual.

    You should use something like LINT to detect such mistakes, and/or use a strongly-typed language like Pascal...

Children
No data