Article View: comp.std.c
Article #2358Re: typedefing functions (Re: Is typedef char BUFFER[20] legal?)
From: Erik Naggum
Date: Mon, 04 Feb 1991 18:28
Date: Mon, 04 Feb 1991 18:28
47 lines
2054 bytes
2054 bytes
In article <1991Feb4.053613.3758@watmath.waterloo.edu>, David Tanguay writes:
> Our compiler had a neat bug with this. It would accept, e.g.,
> typedef int f( int a ) { return a+1; }
> "f" would be a type thereafter in that file, but it was also created
> as an external visible only outside that file. Syntactically typedef
> is the same as static or extern.
> Is the above typedef valid in ANSI-C (as a typedef)? It's not a
> valid function declaration (has to be static or extern), but I can't
> recall anything making it an invalid typedef.
No. You cannot achieve function type through typedef. I remember
this phrase from the standard, but can't find it right now. Note that
you can say
typedef int f (int a, char *b);
and later say
f foo, bar, zot;
and
f *functab[3] = { foo, bar, zot, };
The functions would be declared
f foo
{ ... }
f bar
{ ... }
f zot
{ ... }
This will, naturally, make programs like ctags somewhat less likely to
find the functions, but it's a very good way to provide consistent
interface to functions that are referenced only through function
pointers.
--
[Erik Naggum] <enag@ifi.uio.no>
Naggum Software, Oslo, Norway <erik@naggum.uu.no>
Technical Details
Message-ID:
<ENAG.91Feb4192806@holmenkollen.ifi.uio.no>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!ugle.unit.no!nuug!ifi!enagReferences:
<1212@tredysvr.Tredydev.Unisys.COM> <1991Jan29.210100.8105@zoo.toronto.edu> <22642@netcom.UUCP> <1991Feb3.000128.15980@zoo.toronto.edu> <1991Feb4.053613.3758@watmath.waterloo.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!ugle.unit.no!nuug!ifi!enag From: enag@ifi.uio.no (Erik Naggum) Newsgroups: comp.std.c Subject: Re: typedefing functions (Re: Is typedef char BUFFER[20] legal?) Message-ID: <ENAG.91Feb4192806@holmenkollen.ifi.uio.no> Date: 4 Feb 91 18:28:19 GMT References: <1212@tredysvr.Tredydev.Unisys.COM> <1991Jan29.210100.8105@zoo.toronto.edu> <22642@netcom.UUCP> <1991Feb3.000128.15980@zoo.toronto.edu> <1991Feb4.053613.3758@watmath.waterloo.edu> Sender: enag@ifi.uio.no (Erik Naggum) Followup-To: comp.std.c Organization: Naggum Software, Oslo, Norway Lines: 47 In-Reply-To: datangua@watmath.waterloo.edu's message of 4 Feb 91 05:36:13 GMT