nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

include: Fixed null struct may caused build issue.

Open easonxiang opened this issue 2 years ago • 8 comments

Some compiler do not allowed null structure.

Signed-off-by: xiangdong6 [email protected]

Summary

Impact

Testing

easonxiang avatar Jul 28 '22 07:07 easonxiang

Some compiler do not allowed null structure. @easonxiang

How can we reproduce the error?

masayuki2009 avatar Jul 28 '22 10:07 masayuki2009

Some compiler do not allowed null structure. @easonxiang

How can we reproduce the error?

We are trying to support Windows simulator based on visual studio. This issue can be reproduced with VS2019.

easonxiang avatar Jul 28 '22 12:07 easonxiang

Just a note, there is no need to reproduce this. Empty struct/unions are in fact undefined behaviour according to C standard. So one way or another this should be fixed.

At least one type specifier shall be given in the declaration specifiers in each declarationand in the specifier-qualifier list in each struct declaration and type name.

mlyszczek avatar Jul 29 '22 23:07 mlyszczek

Just a note, there is no need to reproduce this. Empty struct/unions are in fact undefined behaviour according to C standard. So one way or another this should be fixed.

At least one type specifier shall be given in the declaration specifiers in each declarationand in the specifier-qualifier list in each struct declaration and type name.

@mlyszczek could you give a link in spec which state that the empty struct/union is invalid?

xiaoxiang781216 avatar Jul 30 '22 14:07 xiaoxiang781216

Why can this not be handled in the same way with Kconfig? CONFIG_NET_HAVE_DMAC is set for CONFIG_NET_ETHERNET || CONFIG_NET_6LOWPAN || CONFIG_NET_BLUETOOTH || defined(CONFIG_NET_IEEE802154 Then omit the union if CONFIG_NET_HAVE_DMAC is not set?

Yes, @easonxiang please change to:

#if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_NET_6LOWPAN) || \
    defined(CONFIG_NET_BLUETOOTH) || defined(CONFIG_NET_IEEE802154)
  union
  {
#  ifdef CONFIG_NET_ETHERNET
    /* Ethernet device identity */
    struct ether_addr ether;    /* Device Ethernet MAC address */
#  endif
#  if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_BLUETOOTH) || \
      defined(CONFIG_NET_IEEE802154)
  /* The address assigned to an IEEE 802.15.4 or generic packet radio. */

    struct netdev_varaddr_s radio;
#  endif
  } d_mac;
#endif

xiaoxiang781216 avatar Jul 30 '22 14:07 xiaoxiang781216

Just a note, there is no need to reproduce this. Empty struct/unions are in fact undefined behaviour according to C standard. So one way or another this should be fixed.

At least one type specifier shall be given in the declaration specifiers in each declarationand in the specifier-qualifier list in each struct declaration and type name.

@mlyszczek could you give a link in spec which state that the empty struct/union is invalid?

6.7.2.1.7 of ISO/IEC 9899:1999 standard

The presence of a struct-declaration-list in a struct-or-union-specifier declares a new type, within a translation unit. The struct-declaration-list is a sequence of declarations for the members of the structure or union. If the struct-declaration-list contains no named members, the behavior is undefined. The type is incomplete until after the } that terminates the list

mlyszczek avatar Jul 30 '22 15:07 mlyszczek

====================================================================================
Configuration/Tool: sim/tcploop
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Building NuttX...
neighbor/neighbor_lookup.c: In function 'neighbor_match':
Error: neighbor/neighbor_lookup.c:82:38: error: 'struct net_driver_s' has no member named 'd_mac'
   82 |       memcpy(&info->ni_laddr->u, &dev->d_mac, info->ni_laddr->na_llsize);
      |                                      ^~
make[1]: *** [Makefile:76: neighbor_lookup.o] Error 1
make[1]: Target 'libnet.a' not remade because of errors.
make: *** [tools/LibTargets.mk:65: net/libnet.a] Error 2
make: Target 'all' not remade because of errors.
/github/workspace/sources/nuttx/tools/testbuild.sh: line 290: /github/workspace/sources/nuttx/../nuttx/nuttx.manifest: No such file or directory
  Normalize sim/tcploop

masayuki2009 avatar Aug 01 '22 02:08 masayuki2009

ND protocol need mac address to do the translation between IPv6 address and MAC address, I guess some dependence miss here.

xiaoxiang781216 avatar Aug 01 '22 02:08 xiaoxiang781216