Użytkownik Magnus Fromreide <[EMAIL PROTECTED]> napisał:
>On Sat, Jan 15, 2005 at 03:40:04PM +0530, Nakul Aggarwal wrote:
>> Hi,
>>   Whenever i try to compile net-snmp library using g++ ...it gives
>> folowoing errors :
>>  
>>  ========================ERROR=============
>>  -- conflicting types for `struct oid\'
>>  /usr/include/net-snmp/types.h:47: previous declaration as `typedef
>>  u_long oid\'
>>  oid_defn.h:14: field `Oid\' has incomplete type
>>  initializers_oid.cpp: In function `void initialize (oid *)\':
>>  initializers_oid.cpp:11: `struct oid\' has no member named `Oid\'
>>  initializers_oid.cpp:11: `struct oid\' has no member named `Oid\'
>>  initializers_oid.cpp:12: `struct oid\' has no member named `Oid\'
>>  ==============END========================
>
>Here the compiler complains since
>
>struct oid { /* whatever */ };
>
>is indeed incompatible with
>
>typedef u_long oid; /* From include/net-snmp/types.h */
>
>and then it goes on to say that the typedef lacks the member named Oid.
>
>>  Isnt Net-Snmp library compatible with C++ ?
>
>I have never had any major problems :-)
>
>>  =================code for initializers_oid.cpp==========
>>  #include "oid_defn.h"
>>  
>>  void initialize (struct oid *given)
>>  {
>>     struct oid *op = given;
>>     init_snmp("asynchapp");
>>     //struct host ho = Router_struct.Ip;
>>     /* parse the oids */
>>     while (op->Name)
>>     {
>>        op->OidLen = sizeof(op->Oid)/sizeof(op->Oid[0]);
>>        if (!read_objid(op->Name, op->Oid, &op->OidLen))
>>        {
>>           snmp_perror("read_objid");
>>           exit(1);
>>        }
>>        op++;
>>     }
>>  }
>>  ================================
>>  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;
>>  };
>
>This is the part I utterly fail to comprehend - what netsnmp file provides 
>this definition of struct oid? I fail to find it and would like to get a
>reference. (No, I have no file named oid_defn.h)
>
>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.

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).

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

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