What's the syntax for making a typedef for a function pointer? I remember it was different from other typedefs.
Thanks!
Quote from: iago on December 10, 2003, 01:57 PM
What's the syntax for making a typedef for a function pointer? I remember it was different from other typedefs.
Thanks!
typedef rettype (callconvopt *opt name)(paramsopt);
e.g. typedef int (__stdcall * type1)(int);
typedef void (type2)();
Note that when using type2, you'll have to declare variables like this:
type2* ptr;
Some of these may be Visual C++-specific.
#1000
VS specific is fine here.
Thanks!
Is there a better way to do this?
typedef bool (__fastcall *FCString)(char*);
typedef bool (__fastcall *FCStringInt)(char*, int);
typedef bool (__fastcall *FCVoid)(void*, void*);
.....
like, overloading? Or am I just going to have to make a list of what I need?
Thanks! :)
That's the best way...
Quote from: iago on December 10, 2003, 02:59 PM
Is there a better way to do this?
typedef bool (__fastcall *FCString)(char*);
typedef bool (__fastcall *FCStringInt)(char*, int);
typedef bool (__fastcall *FCVoid)(void*, void*);
.....
like, overloading? Or am I just going to have to make a list of what I need?
You might be able to make it work by leaving out the parameter list, but then the compiler won't be able to validate that you're passing the right parameters. If you decide to make a list, I'd suggest using vi substitutions to reduce repetitive typing. ;)
Start with:
FC<type>|<arglist>
:%s/^\(.*\)|\(.*\)$/typedef bool (__fastcall *\1)(\2);/
Result:
typedef bool (__fastcall *FC<type>)(<arglist>);
regex is sexy as hell!
Or I can just add them as I need them :P
Quote from: Kp on December 10, 2003, 06:28 PM
Start with:
FC<type>|<arglist>
:%s/^\(.*\)|\(.*\)$/typedef bool (__fastcall *\1)(\2);/
Result:
typedef bool (__fastcall *FC<type>)(<arglist>);
What is this weird regex syntax? You're escaping characters that you
want regex to treat specially! I want regex to work like /^(.*)\|(.*)$/ .... I thought that was how I used to use them too....
Quote from: Adron on December 10, 2003, 10:11 PM
Quote from: Kp on December 10, 2003, 06:28 PM
Start with:
FC<type>|<arglist>
:%s/^\(.*\)|\(.*\)$/typedef bool (__fastcall *\1)(\2);/
Result:
typedef bool (__fastcall *FC<type>)(<arglist>);
What is this weird regex syntax? You're escaping characters that you want regex to treat specially! I want regex to work like /^(.*)\|(.*)$/ .... I thought that was how I used to use them too....
Probably so, but that's the syntax I would feed to vi / vim. Presumably the author decided to violate convention because he thought that replacing literal parentheses would be done more commonly than using them to mark out subpatterns.
Vim is amazing. I love my syntax color highlighting setup, I can read/write source code twice as fast. Also great for spotting syntax errors :d
Quote from: iago on December 10, 2003, 02:59 PM
Is there a better way to do this?
typedef bool (__fastcall *FCString)(char*);
typedef bool (__fastcall *FCStringInt)(char*, int);
typedef bool (__fastcall *FCVoid)(void*, void*);
.....
like, overloading? Or am I just going to have to make a list of what I need?
Thanks! :)
#define DefFCType1(type) typedef bool (__fastcall *FC_##type)(type)
#define DefFCType2(type1, type2) typedef bool (__fastcall *FC_##type1##_##type2)(type1, type2)
typedef char* pchar;
typedef void* pvoid;
DefFCType1(pchar);
DefFCType2(pchar, int);
DefFCType2(pvoid, pvoid);
((FC_pvoid_pvoid)f)(a, b);
ewwwwwwwww