RE: [Dev-C++] Array of function pointers
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-06-30 20:34:34
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Abhijit Shylanath
> Sent: Sunday, June 30, 2002 9:27 PM
> To: Dev-C++ Mailing List
> Subject: [Dev-C++] Array of function pointers
>
>
> Sorry for my repeated OT posts, but I don't subscribe to many
> lists because
> they have too much of traffic, and poor little me has a
> dial-up account. Of
> all the lists I do subscribe to, Dev-C++ seems to have the most
> knowledgeable (and tolerant) people.
>
> Having finished buttering you up, here's my question:
Always ask. That is why this list is for. Coders talking with coders. :)
> How do I create an array of function pointers?
>
> I declare a function pointer as:
>
> void (*fnPtr)(int arg1) = fn;
Or better: void (*fnPtr)(int);
> I tried making an array like this:
>
> void *(*fnPtrs)(int)
This is a pointer to a function returning void * and getting an int.
>
> Didn't work.
>
> void (*fnPtrs)(int)[] = { fn, foo, NULL };
void (*fnPtrs[])(int) = { fn, foo, NULL };
Or if you cannot think that big, you can make things simpler:
typedef void (*p2f)(int);
p2f fnPtrs[]= { fn, foo, NULL };
> Didn't work either.
>
> Ultimately, I got frustrated and made an array of dwords:
>
> dword fnPtrs[] = { (dword)fn, (dword)foo, (dword)NULL };
>
> This worked, without any warnings. Is this portable and safe?
It depends on what dword is, but it doesn't sound safe.
> Is there any
> other ANSI way of making an array of function pointers?
>
> Thanks for any help.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|