c - Warn if another typedef'd name of a type is used in an argument list -
consider large project, many types typedef'd, e.g.
typedef int age; typedef int height; and functions getting arguments of types:
void printperson(age a, height h) { printf("age %d, height %d\n", a, h); } is there way warn @ compile time, if arguments of wrong type, e.g.
age = 30; height h = 180; printperson(h, a); /* no warning, because , h both integers */ does gcc (or static code analysis tool) have option warn in such cases?
there no built-in support in gcc.
there a feature request add this, based on sparse nocast attribute. however, hasn't been implemented. if can use sparse, though, marking each typedef __attribute__((nocast)).
in c++ can making wrapper classes rather typedefs, , not defining implicit conversions them.
Comments
Post a Comment