delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/12/11/19:51:31

From: naisbodo <naisbodo AT enteract DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Help! function typedef
Date: 12 Dec 2000 00:45:44 GMT
Lines: 43
Message-ID: <913sfo$fil$1@bob.news.rcn.net>
References: <3a30b1a8$0$24264 AT diablo DOT uninet DOT ee> <006101c06103$dc9dd020$aa4d57cb AT spunky> <3a34d45e$0$24309 AT diablo DOT uninet DOT ee> <01c06396$d935cd80$b8247d81 AT doug> <83n1e2963c DOT fsf AT mercury DOT st DOT hmc DOT edu>
X-Trace: urI1GHSJD69XpGIMwjHArCk9ne6gHqSCZpfO7oeb9eU=
X-Complaints-To: abuse AT rcn DOT com
NNTP-Posting-Date: 12 Dec 2000 00:45:44 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019