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.
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?