lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] #if can't use enum vaule ETHARP_STATE_EMPTY


From: Edward Kerekes
Subject: [lwip-devel] #if can't use enum vaule ETHARP_STATE_EMPTY
Date: Thu, 14 Feb 2008 13:54:25 -0500

Hi,

Thanks to all involved with this project!

 

While compiling lwIP V1.3.0RC1 I found a minor compiler issue in the module etharp.c line 132:

 

/* Some checks, instead of etharp_init(): */

#if ETHARP_STATE_EMPTY != 0                                      <<<<<<< Line 132 gives compiler warning

#error ETHARP_STATE_EMPTY must be 0 to ensure correct initialization value!

#endif  

 

Line 132 gives the following warning:

 

“Warning C4443: Undefined Macro ‘ETHARP_STATE_EMPTY‘ is taken as 0.”

 

ETHARP_STATE_EMPTY is defined using an enum and from ANCI C:

            “The #if line evaluates a constant integer _expression_ (which may not include sizeof, casts, or enum constants).”

 

1. May I suggest removing the 3 lines of code at line 132 and

2. Adding the comment “ETHARP_STATE_EMPTY must be 0 to ensure correct initialization value!” to exiting line 88.

 

Existing code:

enum etharp_state {

  ETHARP_STATE_EMPTY,       <<<<<<<<<<<<<< Line 88.

  ETHARP_STATE_PENDING,

  ETHARP_STATE_STABLE

};

 

Same code with new comment:

enum etharp_state {

  ETHARP_STATE_EMPTY,   /* “ETHARP_STATE_EMPTY must be 0 to ensure correct initialization value!” */

  ETHARP_STATE_PENDING,

  ETHARP_STATE_STABLE

};

 

I would think the comment would prevent someone from re-ordering the enum labels in the future...

 

Thanks again to all who have contributed to this fine project.

 

Ed

 

Here is a patch if it helps:

 

 

 

Index: etharp.c

===================================================================

--- etharp.c        (revision 226)

+++ etharp.c     (working copy)

@@ -85,7 +85,7 @@

 #define ARPH_PROTOLEN_SET(hdr, len) (hdr)->_hwlen_protolen = htons((len) | (ARPH_HWLEN(hdr) << 8))

 

 enum etharp_state {

-  ETHARP_STATE_EMPTY,

+  ETHARP_STATE_EMPTY,  /* "ETHARP_STATE_EMPTY must be 0 to ensure correct initialization value!" */

   ETHARP_STATE_PENDING,

   ETHARP_STATE_STABLE

 };

@@ -129,9 +129,9 @@

 

 

 /* Some checks, instead of etharp_init(): */

-#if ETHARP_STATE_EMPTY != 0

-#error ETHARP_STATE_EMPTY must be 0 to ensure correct initialization value!

-#endif

+//#if ETHARP_STATE_EMPTY != 0

+//#error ETHARP_STATE_EMPTY must be 0 to ensure correct initialization value!

+//#endif

 #if (LWIP_ARP && (ARP_TABLE_SIZE > 0x7f))

   #error "If you want to use ARP, ARP_TABLE_SIZE must fit in an s8_t, so, you have to reduce it in your lwipopts.h"

 #endif

 

 

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]