On Sat, Jan 15, 2005 at 09:29:16PM +0100, [EMAIL PROTECTED] wrote:
> U?ytkownik Magnus Fromreide <[EMAIL PROTECTED]> napisa?:
> >On Sat, Jan 15, 2005 at 03:40:04PM +0530, Nakul Aggarwal wrote:
> >>  ================================
> >>  while Oid_defn.h contains the standard struct OID defn of net-snmp
> >> library. i.e.
> >>  struct oid {
> >>    const char *Name;
> >>    oid Oid[MAX_OID_LEN];
> >>    int OidLen;
> >>  };
> >
> >Oh yes, the above struct would be erraneous even in isolation since it tries
> >to recursively define the member Oid as an array of the incomplete type
> >struct oid.
> 
> I seem that this code is OK for a C compiler and it is incorrect for a C++ 
> compiler.

Yes, this is one of the differences between C and C++.

> In C, 'struct A' is a separate type from 'A'. In the code above, oid Oid[...] 
> refers to the typedef (i.e., u_long), and is fine.
> 
> A problem appears in C++, as in C++ 'struct A' is (roughly) equivalent to 
> 'class A' and to 'A' (it is no more needed to precede 'A' with struct when 
> the type is used).

Im C++ the only difference between class A and struct A is that in the latter
case the default visibility is public while it is private in the first case.

Additionally the C++ compiler does something similar to: (Note, C, not C++)

struct A;
typedef struct A A;
struct A {
 ...
};

which you noted above.

> I believe that for C++ compatibility 'extern "C"' declaration should be used 
> (usually combined with a #ifdef __cpluspluc directive).

If you look once more you will find that all net-snmp headers do that unless
there is some that got missed - if that is the case I am certain that a
bug report would be appreciated.

On the other hand that is no universal solution, all it does is that it 
tells the C++ compiler that the names are C names and thus shouldn't be subject
to name mangling and that they should be called with C calling conventions.

The headers still have to be written using the common subset of C and C++.

> Marek


-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to