Reply embedded...
--- In [email protected], Ray Devore <[EMAIL PROTECTED]> wrote:
>
> I keep seeing two different ways to define a struct
> (see below). What is the benefit of doing the typedef
> over just defining the struct with a tag?
In C language prior to C99, the struct tag alone cannot be used to declare
an object of struct type:
struct MY_STRUCT
{
...
};
MY_STRUCT myObj; /* Error in C90 */
The keyword 'struct' is required:
struct MY_STRUCT myObj; /* OK */
Therefore 'typedef' is used to create an alias to "struct [tag] {...}" to
save some typing:
typedef struct
{
...
} MY_STRUCT;
MY_STRUCT myObj; /* OK */
In C++, the tag name can be used as a type without the 'struct' keyword:
struct MY_STRUCT
{
...
};
MY_STRUCT myObj; /* OK in C++ */
C99 follow suit and adapted this syntax. For backward compatibility, the
original syntax still acceptable in C++ and C99.
> Is one more efficient than the other?
In C90 compiler, a typedef would save some keystrokes whenever the struct is
used. So in that sense, you can say it is more efficient.
It would have no effect to the compiled code.
HTH
Shyan