Protecting me from myself

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Protecting me from myself

1,781 Views
Nevo
Contributor I
I realize that I'm not the world's best C programmer. As a result, on the rare occasions I program in C, I like to crank up compiler settings to their most picky settings, so the compiler warnings and errors will alert me when I'm about to do something boneheaded.  (Or when I'm about to make an easy-to-make mistake.)
 
I'd like to do the same with CodeWarrior for the HCS08. I observed, for instance, that CodeWarrior will allow me to assign the value 65535 to a 16-bit signed integer. I would like CodeWarrior to warn me when I do things like that.
 
Can anyone suggest appropriate settings to turn the compiler up to 'nitpicky mode'?
 
Thanks,
 
-Nevo
Labels (1)
Tags (1)
0 Kudos
Reply
2 Replies

636 Views
tmyint
Contributor I
hey Nevo,

This is what I think. Assigning a value 65535 to a signed interger will probably not generate a compile error because the compiler will just take that number ( 0xFFFF) which is -1 in decimal (signed) and dump it in. So theres a very good chance that your calculation will be wrong coz the compiler thinks its a -1 instead of 65535 that you probably wanna use.

I tried changing the compiler settings to "strict ANSI", which is what our moderator suggested here also, but some typedefs that PE generated was no longer being recognized. I have noticed that CW compiler will let you get away with some things that other compilers wont.

Regards,
Thet
0 Kudos
Reply

636 Views
J2MEJediMaster
Specialist I
You want to go the compiler settings panel, and then for language settings switch on the ANSI standard enforcement ("ANSI strict" for the HCS12x tools I'm looking at.) That should catch a number of problems. There may be other type-checking features you can enable. These settings vary from compiler to compiler so I can't give you an exact answer.
 
---Tom
0 Kudos
Reply