Archive for the ‘type’ tag
Type-checking in gcc
In linux/kernel.h, there is such a macro
/*
* min()/max() macros that also do
* strict type-checking.. See the
* "unnecessary" pointer comparison.
*/
#define min(x,y) ({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x < _y ? _x : _y; })
In order to do strict type-checking, that “unnecessary” pointer comparison is, however, necessary. If we compare two distinct pointers without a cast, gcc will complain about it, so that we are able to figure out where things go wild.
To go further, we need some knowledge about Type System, which means “a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute”. That requires an understanding of computer language theories, which is beyond my knowledge now. I shall figure it out in the future.
http://en.wikipedia.org/wiki/Type_system