In article <pa************ *************** *@this.address>
Duncan Muirhead <no***@this.add ress> wrote:
If I understand [Keith Thompson] correctly, there is a special rule
for declarations of function (pointer) types ...
Not exactly. See the article I already referred you to elsewhere in
this thread.
As for typedefs for struct types, I suspect your right, but would say:
I, and indeed the people I've worked with, only ever use the typedef'd
names in code and so having the two names is limited to the type
declaration.
In that case, use the method I outlined in that same article.
Note that you can use the *same* name for the typedef-name and
the structure tag:
struct Foo;
typedef struct Foo Foo;
Note also that you can write "struct Foo;" (at file scope) as many
times as you like, while you can only have the typedef line once.
Hence, in some (relatively rare) situations, you *must* use only
the tag. For instance, if zog.h declares a prototype for a function
zog() that operates on a "Zog", while glik.h declares a prototype
for a function glik() that happens to take a "Zog" as an argument
but -- for whatever reason -- glik.h cannot #include "zog.h" nor
require that those who include glik.h also include zog.h first,
then glik.h must use "struct Zog" instead of "Zog:
/* glik.h */
struct Zog;
void glik(struct Zog *);
/* zog.h */
struct Zog;
typedef struct Zog Zog;
void zog(Zog *);
struct Zog {
Zog *next;
... other fields ...
};
(Of course, everything becomes much simpler if you just throw away
the typedef, and type out the word "struct". Then you no longer
need some sort of typographic gimmick -- in this case, the initial
capital letter -- to distinguish typedef-identifiers from other
ordinary identifiers. Not that a *compiler* needs such a gimmick,
but if you do not use one, programmers will make more mistakes.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.