0

I see this compilation error "has no member named" for some of the union elements.

snmp_xmas.c:129: error: 'xmas_datatype_value_t' has no member named 'int8'
snmp_xmas.c:132: error: 'xmas_datatype_value_t' has no member named 'int16'

I dont see any issue with the member definion. The union definion is as follows.

typedef union {
/**
 * Value for XMAS_ITEM_DATATYPE_BITS
 */
xmas_datatype_bits_t         bits;
/**
 * Value for XMAS_ITEM_DATATYPE_BOOL
 */
xmas_datatype_bool_t boolean;
/**
* Value for XMAS_ITEM_DATATYPE_CERRNO
 */
xmas_datatype_cerrno_t       cerrno;
/**
 * Value for XMAS_ITEM_DATATYPE_DATETIME
 */
xmas_datatype_datetime_t     datetime;
/**
 * Value for XMAS_ITEM_DATATYPE_EMPTY
 */
xmas_datatype_empty_t        empty;
/**
 * Value for XMAS_ITEM_DATATYPE_ENUM
 */
xmas_datatype_enum_t enumeration;
/**
 * Value for XMAS_ITEM_DATATYPE_IDENTITYREF
 */
xmas_datatype_identityref_t  identityref;
/**
 * Value for XMAS_ITEM_DATATYPE_INT16
 */
xmas_datatype_int16_t        int16;
/**
* Value for XMAS_ITEM_DATATYPE_INT32
*/
xmas_datatype_int32_t        int32;
/**
 * Value for XMAS_ITEM_DATATYPE_INT64
 */
xmas_datatype_int64_t        int64;
/**
 * Value for XMAS_ITEM_DATATYPE_INT8
 */
xmas_datatype_int8_t         int8;
/**
 * Value for XMAS_ITEM_DATATYPE_INTF
 */
xmas_datatype_intf_t        *intf;
/**
 * Value for XMAS_ITEM_DATATYPE_IPV4_ADDR
 */
xmas_datatype_ipv4_addr_t    ipv4_addr;
/**
 * Value for XMAS_ITEM_DATATYPE_IPV6_ADDR
 */
xmas_datatype_ipv6_addr_t   *ipv6_addr;
/**
 * Value for XMAS_ITEM_DATATYPE_IP_ADDR
 */
xmas_datatype_ip_addr_t     *ip_addr;
/**
} xmas_datatype_value_t;

All the xmas datatypes are defined in a single header file and is included in my .c file which refers the union members. The code snippet is pasted below.

cerrno
xmibd_convert_xmas_to_XXX(xmas_item_datatype_t    *xmas_datatype,
                       xmas_datatype_value_t   *xmas_value,
                       struct sa_do_value     **ret_value)
{
:
:
:

switch (*xmas_datatype) {
    case XMAS_ITEM_DATATYPE_BITS:
        out_value = sa_do_value_new_unsigned_long(xmas_value->bits);
        break;
    case XMAS_ITEM_DATATYPE_BOOL:
        out_value = sa_do_value_new_boolean(xmas_value->boolean);
        break;
    case XMAS_ITEM_DATATYPE_CERRNO:
        out_value = sa_do_value_new_unsigned_int(xmas_value->cerrno);
        break;
    case XMAS_ITEM_DATATYPE_EMPTY:
        out_value = sa_do_value_new_boolean(xmas_value->empty);
        break;
    case XMAS_ITEM_DATATYPE_DATETIME:
        out_value = sa_do_value_new_datetime(xmas_value->datetime);
        break;         
    case XMAS_ITEM_DATATYPE_INT8:
         out_value = sa_do_value_new_byte(xmas_value->int8);
         break;
     case XMAS_ITEM_DATATYPE_INT16:
         out_value = sa_do_value_new_short(xmas_value->int16);
         break;
:
:
}

Any pointers to the possible issue would be highly appreciated. Thanks,

timrau
  • 22,578
  • 4
  • 51
  • 64
Abhi V
  • 89
  • 1
  • 3
  • 10
  • You probably also have code elsewhere that does `#define int8` something. Try `#ifdef int8` followed by `#error aha`, in the header – M.M Apr 28 '14 at 05:44
  • Alternatively, look up how `xmas_datatype_int8_t` is defined – M.M Apr 28 '14 at 05:46
  • 1
    Please show the actual code you compile, not the extract. Your `typedef` shown won't compile because it doesn't end with a semicolon after the close brace, and there isn't a name there either. So, either you chopped off some crucial information or you're actually using something else. I'd be leery of using names like `int8` and `int16` as members; there's too much risk (in my book, based on experience) of there being data types of those names. (One of the systems I worked on had a set of data types like `int1`, `int2`, `int4` and … well, it ran into problems with `int8` — 8 bytes or 8 bits?) – Jonathan Leffler Apr 28 '14 at 06:44
  • int8 and uint8 etc were very commonly used typedefs in C, before C99 standardized them to be called int8_t and uint8_t. – Lundin Apr 28 '14 at 06:46
  • Even StackOverflow parser highlights your `int8` and `int16` members as types. Are you sure there is no other name you can use for those members ? – Dabo Apr 28 '14 at 06:52
  • I tried renameing int8 to int8_temp etc. But the same error is coming. so, it doesnt seem to be related to the variable name. – Abhi V Apr 28 '14 at 07:02

1 Answers1

0

The issue was related to a duplicate obsolete path for the header file mentioned in the Makefile. It was referring to the wrong path, so obviously my changes weren't getting affected.

Abhi V
  • 89
  • 1
  • 3
  • 10