D - User defined pragma
- Robert (29/29) Jan 04 2004 In C99, one can define pragma by using _Pragma operator.
In C99, one can define pragma by using _Pragma operator. It helps to unify several pragmas with the same function. e.g. #if defined(VendorA) #elif defined(VendorB) #elif defined(VendorC) #endif pragma_fastcall void foo() { ... } pragma_fastcall void bar() { ... } pragma_fastcall void baz() { ... } I suggest user-defined pragmas, e.g.: pragma User_foo(param) { version(VendorA) { pragma(VendorA_foo, param); } else version(VendorB) { pragma(VendorB_bar, param, 0); } else version(VendorC) { pragma(VendorC_foo, 0, param); } else { pragma(error, "User_foo: not supported."); // I also suggest error pragmas. } } pragma(User_foo, 4) struct A { int a, b, c; } pragma(User_foo, 8) struct B { int a, b, c; } pragma(User_foo, 16) struct C { int a, b, c; }
Jan 04 2004