January 05, 2004 User defined pragma | ||||
---|---|---|---|---|
| ||||
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) # define pragma_fastcall _Pragma("call_func_fast") #elif defined(VendorB) # define pragma_fastcall _Pragma("fastcall") #elif defined(VendorC) # define pragma_fastcall _Pragma("__fastcall") #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; } |
Copyright © 1999-2021 by the D Language Foundation