• Welcome to Valhalla Legends Archive.
 

Typedef'ing functions pointers

Started by iago, December 10, 2003, 01:57 PM

Previous topic - Next topic

iago

What's the syntax for making a typedef for a function pointer?  I remember it was different from other typedefs.  

Thanks!
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Skywing

#1
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

iago

This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


iago

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! :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


DarkMinion


Kp

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>);
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Etheran


iago

Or I can just add them as I need them :P
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Adron

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....


Kp

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.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

wut

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

Yoni

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