Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
#define syntax
Message
De
15/02/2013 22:30:36
 
 
À
Tous
Information générale
Forum:
Visual C++
Catégorie:
Codage, syntaxe et commandes
Titre:
#define syntax
Divers
Thread ID:
01566217
Message ID:
01566217
Vues:
47
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! :-)
Répondre
Fil
Voir

Click here to load this message in the networking platform