Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
#define syntax
Message
From
15/02/2013 22:30:36
 
 
To
All
General information
Forum:
Visual C++
Category:
Coding, syntax & commands
Title:
#define syntax
Miscellaneous
Thread ID:
01566217
Message ID:
01566217
Views:
49
Hello everybody. I have a case where I'm using this #define syntax to create function pointers called callback_dragDrop and callback_dragStart, amongst others:
#define defineCallback2(x, arg1, arg2) \
    void (WINAPI *callback_ ## x )( arg1, arg2 );

#define defineCallback3(x, arg1, arg2, arg3) \
    void (WINAPI *callback_ ## x )( arg1, arg2, arg3 );
Note: The pattern above is actually extended up to defineCallback8 for arg1..arg8.

In my code I use it like this:
defineCallback2(dragDrop,  int foo, int noo)
defineCallback3(dragStart, int foo, int noo, int koo)
It works, but I'm thinking there's probably a way to make one function which tests for the presence of argN arguments, and uses only those which are present (like the variable parameters passed to printf). Perhaps something like #define defineCallback(x, y..), where I can use "y" in place of "arg1, arg2" and it conveys everything that's passed regardless of how many parameters there are ??

Any ideas? TYIA! :-)
Reply
Map
View

Click here to load this message in the networking platform