Mail Archives: djgpp/2000/12/08/05:48:46
Message-ID: | <006101c06103$dc9dd020$aa4d57cb@spunky>
|
From: | "JB" <jamesb AT northnet DOT com DOT au>
|
To: | <djgpp AT delorie DOT com>
|
References: | <3a30b1a8$0$24264 AT diablo DOT uninet DOT ee>
|
Subject: | Re: Help! function typedef
|
Date: | Fri, 8 Dec 2000 21:44:36 +1100
|
MIME-Version: | 1.0
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Mailer: | Microsoft Outlook Express 5.50.4133.2400
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4133.2400
|
X-MIME-Autoconverted: | from 8bit to quoted-printable by bart.northnet.com.au id VAA19281
|
X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id FAA01588
|
Reply-To: | djgpp AT delorie DOT com
|
typedef int MY_FUNC_TYPE;
MY_FUNC_TYPE func(void)
{
return 0;
}
But it looks as if you were looking for a pointer to a function, in which
case you could do this:
typedef int (* MY_FUNC_TYPE)(void);
MY_FUNC_TYPE = my_func;
... call it like this:
MY_FUNC_TYPE();
int my_func(void)
{
return 0;
}
Another example:
struct func_struct {
void (* say_something)(char *); /* pointer to function that takes a
char pointer and returns NULL */
int (* some_function)(int, int); /* takes 2 ints and returns their
product */
} func_structure;
int main(int argc, char **argv, char **envp)
{
struct func_structure f_struct;
int ival;
f_struct.say_something = hello;
f_struct.some_function = product;
f_struct.say_something();
ival = f_struct.some_function(5, 10);
printf("ival = %d\n", ival);
return 0;
}
void hello(char *str)
{
printf("%s\n", str);
}
int product(int i, int j)
{
return i * j;
}
----- Original Message -----
From: "Tonu Aas" <tonu AT ids DOT ee>
Newsgroups: comp.os.msdos.djgpp
To: <djgpp AT delorie DOT com>
Sent: Friday, December 08, 2000 8:55 PM
Subject: Help! function typedef
> Why doesnt this work ?
>
> typedef int (MY_FUNC_TYPE)(void);
>
> MY_FUNC func
> {
> return 0;
> }
>
> Error: syntax error before `{'
>
> Tõnu.
>
>
- Raw text -