On 04/22/11 14:21, Remco wrote:
Mike Williams wrote:

[asbestos suit donned? check!]

The style(9) man page contains the statement

    Don't use the same name for a struct tag and a typedef, as this makes
    the code unusable from C++.

My question is how does this make the code unusable from C++?

An interweb search doesn't turn up any examples or explanations, just
the usual explanations of why you need typedef in C but not in C++.
While I know C the subtleties of C++ are beyond me.  The only detailed
references seem to be historic variations on the BSD style page.

Not one to take inscriptions on a tablet without question, it would be
nice to understand the reason for this statement.


If I understand you correctly you'd like to do something like:
typedef struct some_type some_type;

AFAICT when a struct is defined in C++, e.g.:
struct some_type {
    ...
};
variables can be declared as, either:
struct some_type some_var;
or:
some_type some_var;

So 'some_type' is already sort of an implicit typedef of 'struct some_type'.

Yep, I have seen that, but that does not explain what the problem is with the having a struct tag and typedef the same.

I work in the C world. I know and understand C namespaces and how typedef works. If I write an API that may be picked up by a C++ application I'd like to know why doing

typedef struct FOO { ... } FOO;

is unusable in the C++ world.

I'm guessing it is not a syntactic problem - a C++ compiler will compile the code - but a semantic one resulting in unexpected behaviour. Or possibly worse. I was hoping to find a "dont use same name for struct tag and typedef in C++ because of this unwanted behaviour ..." explanation and not just be another monkey hosed down going for the banana.

--
Mike

Reply via email to