Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Non C/C++ user here...

A lot of the problems are due to the assumption an integer is big enough to store a pointer.

Just wondering: is there a way to make the compiler barf if such an assignment is done? Or for generating a runtime error if the assignment doesn't fit?



I believe gcc will warn about this, unless you explicitly pass -Wno-pointer-to-int-cast, which will "suppress warnings from casts from a pointer to an integer type of a different size."


Using stricter compiler flags is often the fastest and easiest way to catch such bugs. Here at CMU, we usually require all assignments for undergrad C/C++ courses to compile with no warnings using "gcc -ansi -pedantic -Wall -Wextra".

If you never acquire the habit of writing sloppy code and ignoring warnings, it's not even that bad. In fact, it's only the kids who already know C coming in who complain about the stricter flags.


Relevant:

Comparing capabilities of PVS-Studio and Visual Studio 2010 in detecting defects in 64-bit programs - http://www.viva64.com/en/a/0066/

64 bits, Wp64, Visual Studio 2008, Viva64 and all the rest - http://www.viva64.com/en/a/0021/


Yes they can. VC++ has a setting for 64bit compatibility warnings. I would be surprised if g++ didn't.


Right, I think that almost all the problems state are int-to-something conversion (one was about putting a number into a double).

Used to be (old guy talking) 'int' meant 'register size' so on a 64-bit target it whould be 64 bits. Whereupon all the 'bugs' evaporate.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: