Multiple typedefs

Dave Collier-Brown dave at lethe.UUCP
Mon May 1 01:33:06 AEST 1989


In article <2322 at lethe.UUCP> drew at lethe.UUCP (Drew Sullivan) writes:
| typedef unsigned int foo_t;		/* from include file 1 */
| extern foo_t foo(void);
| typedef unsigned int foo_t;		/* from include file 2 */
| extern foo_t foo(void);

In article <10167 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
| No, the second typedef is syntactically invalid.
| The conventional way to guard against this is:
| 	#ifndef _FOO_T_DEFINED
| 	#define	_FOO_T_DEFINED
...

  It is interesting that one has to use ifdefs to protect a redefinition
of a typedef but not of a macro.  In P.J. Plauger's column on Standard C [1]
he comments..

	The committee eventually permitted one form of refefinition,
    however. Plum insisted we allow "benign" redefinition of a macro.
    Loosely speaking, a macro definition is benign if it results in
    essentially the same definition as before. Permitting benign
    redefinition, Plum argues, greately simplifiees writing the same
    definition in multiple #include files. (The Standard C library has
    multiple definitions of the macro NULL, for instance.)
 
  Is there a technical reason for the difference in redefinition rules
for macros -vs- typedefs, or is it present for administrative or
historical reasons?  Or is it an error?

--dave c-b
  ps: the above is something close to the meaning of Drew's initial
  question.
-- 
David Collier-Brown,  | {toronto area...}lethe!dave
72 Abitibi Ave.,      |  Joyce C-B:
Willowdale, Ontario,  |     He's so smart he's dumb.
CANADA. 223-8968      |



More information about the Comp.std.c mailing list