Reputation: 301
I have a c++ program that imports a dll with lots of functions.
//.h file
/*Description: set velocity(short id of axis, double velocity value)*/
typedef short(__stdcall *GT_SetVel)(short profile, double vel);
//.cpp file
/*Description: set velocity(short id of axis, double velocity value)*/
GT_SetVel SetAxisVel = NULL;
...
SetAxisVel = (GT_SetVel)GetProcAddress(GTDLL, "_GT_SetVel@10");
...
SetAxisVel(idAxis, vel);
I want to make it more compact, like
//.h file
/*Description: set velocity(short id of axis, double velocity value)*/
typedef short(__stdcall *GT_SetVel)(short profile, double vel) SetAxisVel = NULL;
//.cpp file
SetAxisVel = (GT_SetVel)GetProcAddress(GTDLL, "_GT_SetVel@10");
...
SetAxisVel(idAxis, vel);
It may sound ridiculous. Is there a syntax similar to the above, where two statements are merged into one and not just placed together into ajacent lines.
The reason is that
(1) I need both the type alias and the function pointer variable,
(2) and it's necessary to have the description comment for both typedef (semantic to have argument description by argument list) and pointer declaration (provide intellisense for later use).
But the type alias is only used once, it seems redundant to insert the same description in two seperate places.
Is there a way to make it more compact? Thanks.
Upvotes: 0
Views: 373
Reputation: 217398
By getting rid of typedef, you may shorten to:
// .cpp
/*Description: set velocity(short id of axis, double velocity value)*/
short(__stdcall *SetAxisVel)(short profile, double vel) = NULL;
SetAxisVel = reinterpret_cast<decltype(SetAxisVel)>(GetProcAddress(GTDLL, "_GT_SetVel@10"));
Upvotes: 1