Re: function pointers
- From: "Tomás Ó hÉilidhe" <toe@xxxxxxxxxxx>
- Date: Sun, 06 Jan 2008 18:16:19 GMT
hifrnds007@xxxxxxxxx wrote in comp.lang.c:
how the function poiners avoids the usage of switch cases?
Here's a typical switch statement:
switch (user_input)
{
case 0: DeleteFile(); break;
case 1: CopyFile(); break;
case 2: RenameFile(); break;
case 4: MoveFile();
}
And here's the function pointer equivalent:
void (*const funcs[4])(void) = {DeleteFile,CopyFile,Renamefile,MoveFile};
funcs[user_input];
--
Tomás Ó hÉilidhe
.
- Follow-Ups:
- Re: function pointers
- From: Michal Nazarewicz
- Re: function pointers
- From: Tomás Ó hÉilidhe
- Re: function pointers
- References:
- function pointers
- From: hifrnds007
- function pointers
- Prev by Date: Re: [OT] Too much current
- Next by Date: Re: function pointers
- Previous by thread: Re: function pointers
- Next by thread: Re: function pointers
- Index(es):
Relevant Pages
|