Mail Archives: djgpp/2000/12/11/19:51:31
[Attribution lost] wrote:
>> > NO NO NO. I wrote:
>> > typedef int (MY_FUNC_TYPE)(void);
>> >
>> > MY_FUNC func
>> > {
>> > return 0;
>> > }
The valid C he might be thinking of is as follows:
typedef int MY_FUNC_TYPE(void);
MY_FUNC_TYPE func;
The C standard gives examples of this kind of typedef to make function
parameters more clear in 6.7.7#7:
[#7] EXAMPLE 4 On the other hand, typedef names can be used
to improve code readability. All three of the following
declarations of the signal function specify exactly the same
type, the first without making use of any typedef names.
typedef void fv(int), (*pfv)(int);
void (*signal(int, void (*)(int)))(int);
fv *signal(int, fv *);
pfv signal(int, pfv);
Actually declaring functions in this manner is less useful, because you
can *only* declare (and prototype) a function with the above; you can't
define one, hence Nate's common macro workaround given below:
Nate Eldredge <neldredge AT hmc DOT edu> wrote:
> #define DECLARE_MY_FUNC(name) int name (void)
It is often accompanied by a typedef for a function to the same type,
in my experience:
#define DECLARE_MY_FUNC(name) int name(void)
typedef int my_func_t(void);
--
naisbodo AT enteract DOT com
- Raw text -