Andreas <a.******@kabsi.atwrites:
Am Wed, 14 Nov 2007 12:03:54 +0000 schrieb Spiros Bousbouras:
>On Nov 14, 11:56 am, Andreas <a.kas...@kabsi.atwrote:
>>i'm going to develope an mp3 encoder and therefor i'm studiing the
source code of lame mp3 encoder. but i'm not able to anderstand the
nixt three lines of the sourde.
struct lame_global_struct;
typedef struct lame_global_struct lame_global_flags;
typedef lame_global_flags *lame_t;
The 2nd line defines "lame_global_flags" to be a name for the type
"struct lame_global_struct" and the 3rd line defines "lame_t" to be a
name for the type "pointer to lame_global_flags". In other words lame_t
is a name for the type "pointer to struct lame_global_struct".
and the fist line? what means it? - no structure of the datatype is
defined?
Please don't top post.
struct lame_global_struct;
It says that there is a struct called lame_global_struct and no more.
It is used when the programmer wants to talk about a structure without
saying anything more about it. In the example above, the programmer
wants to define a synonym for the structure type and for a pointer to
it. There is not much else you can do with it which is sometimes the
whole purpose (look up "opaque types").
There is no need to write it out like that.
typedef struct lame_global_struct lame_global_flags;
typedef lame_global_flags *lame_t;
serves the same purpose (in C). The original may have been written
because, to a C++ compiler, a structure tag is a legal type name and
the code may have once have had things like:
some_function(lame_global_struct *sp);
in it once, or simply the author may have adopted that style because
he/she is used to it from C++.
--
Ben.