Linux-Hams archive - March 1997: DAMA Support in 2.1.27

DAMA Support in 2.1.27

Mike Bilow (izgwq@x9.dk)
Fri, 07 Mar 97 00:50:00 -0000


Joerg Reuter wrote in a message to Mike Bilow:

JR> I´m working on it indeed... In the meantime let me tell you
JR> how I *love* C:

JR> typedef struct foo foo;

JR> void bar()
JR> {
JR> foo *foo;

JR> /* some code so that above declaration scrolled out of
JR> the window */

JR> memset(foo, 0, sizeof(foo));
JR> }

JR> Boom!

JR> Yes, it *is* a dumb error. I had the type "foo" in mind, not
JR> the variable "foo".

You're asking for it if you use the same name for (1) a struct tag, (2) a
typedef'ed equivalent to a struct tag, and (3) a pointer to a struct.

I recommend IBM internal style for this:

typedef struct _foo FOO;

void bar()
{
FOO * pfoo;

memset(pfoo, 0, sizeof(FOO));
}

Note, of course, that this code still allocates only a pointer to type "FOO"
and depends upon "pfoo" being assigned to point to some valid "FOO" object.
Instead, you may want:

typedef struct _foo FOO;

void bar()
{
FOO foo;

memset(&foo, 0, sizeof(FOO));
}

-- Mike