14Fermer16
PolluxLe 18/03/2005 à 18:06
Sasume :
But I thought about another way to use graphlib functions with an additional parameter :
In your .h file :
#define USE_CUSTOM_GRAPHLIB \
#undef graphlib__0000 // fill \
#undef graphlib__0017 // line \
blablabla

You can't write stuff like that in C (actually, you can, but it won't do what you think it does cheeky)
You can't have a preprocessor command in a #define (the preprocessor will in fact believe that you want to stringify the macro parameter 'undef', which does not exist).
What's more, \s are interpreted at a very early stage, meaning your statement really is
#define USE_CUSTOM_GRAPHLIB #undef graphlib__0000 // fill #undef graphlib__0017 // line blablabla
which is equivalent to
#define USE_CUSTOM_GRAPHLIB #undef graphlib__0000

In fact, that was even a feature that was available in early versions of GTC smile (with a different command, #macro)



Hibou> things don't work like that in C, because the compiler could do weird magic between your assignment to a1 and the actual function call. And the default calling convention provides no way to specify that a1 is not destroyed by the function call (I even think you can't change that without recompiling GCC -- don't quote me on this though). Basically, it would be very dirty to do that, and I really don't think you need such a high level of optimization when calling such a slow library... Just declare it as a parameter and pass it every time you need it.