如果你真的,绝对想要禁止原生类型但允许typedefs,我想你总是可以这样做:
#include <stdint.h>
#define int please_use_stdint_typedefs_rather_than_native_types
int main()
{
int32_t good; // Good typedef.
int evil; // Evil native type.
}
Run Code Online (Sandbox Code Playgroud)
$ gcc -c int_forbidden.c
int_forbidden.c: In function ‘main’:
int_forbidden.c:8: error: ‘please_use_stdint_typedefs_rather_than_native_types’ undeclared (first use in this function)
int_forbidden.c:8: error: (Each undeclared identifier is reported only once
int_forbidden.c:8: error: for each function it appears in.)
int_forbidden.c:8: error: expected ‘;’ before ‘evil’
Run Code Online (Sandbox Code Playgroud)
也就是说,在一般情况下,我认为完全禁止原生类型是个好主意.
你可以在这个boost库中提出这些typedef Strong Typedef:http://www.boost.org/doc/libs/1_40_0/boost/strong_typedef.hpp