Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Oct 1996 08:06:29 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        bde@zeta.org.au, jdp@polstra.com
Cc:        current@FreeBSD.org, phk@FreeBSD.org, wollman@lcs.mit.edu
Subject:   Re: <sys/queue.h>
Message-ID:  <199610202206.IAA19365@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>> I agree.  Typedef should only be used for scalar types and function
>> types.
>
>Why do you say that?  There's already precedent for using typedefs
>for structs in, for example, the "DIR" type of <dirent.h>.  And it

An exception that proves the rule.  A real c (sic) programmer would
never use upper case in a type or variable name :-).  <dirent.h> is
POSIX.  I don't know the BSD history of DIR.

>is in line with C++ practice, where the struct, class, or union
>keyword is almost never used outside of the declaration.  (I know,
>this is C, not C++.  But the idea that the name of a type should
>not carry unnecessary information about its representation is a
>valid one.)

At least in the kernel, you need to be intimately aware of the
representation to write space- and time-efficient code.  E.g.,
`auto foo_t foov;' is no good if foo_t might be a large struct,
since the kernel stack is small.

>Another consideration worth noting:  The single example of something
>similar in the ANSI/ISO C standard, offsetof(), uses PHK's approach.
>Again, this is precedent for using a type rather than a structure tag
>as the macro argument.

I didn't completely understood phk's proposal.  You can always use
`struct foo' for the type in offsetof() provided the struct has a tag.  
The queue macros take a "type" arg which is actually a struct tag and
prefix `struct ' to it.  I agree that this is wrong.  My objection is
to using a typedef for `struct foo'.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610202206.IAA19365>