lwip-devel
[Top][All Lists]
Advanced

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

[lwip-devel] Macros


From: Robert
Subject: [lwip-devel] Macros
Date: Tue, 12 Apr 2011 22:39:32 -0400

I would like to see a small change to the print format macros.  At present these macros look like this:


/* Define (sn)printf formatters for these lwIP types */
#define X8_F  "02x"
#define U16_F "hu"
#define S16_F "hd"
#define X16_F "hx"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"

And here is a typical invocation of one of these macros:

LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %"U16_F"\n", port));

So after substition, the result is this:

LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %""hu""\n", port));

Or more readable like this:

LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %"   "hu"   "\n", port)); 

The seperate string get combined, resulting in this:

LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %hu\n", port)); 

It's a rather clever use of macros, which unfortunately my compiler cannot cope with.  My compiler apparently scans the strings after macro insertion but before combining the strings, and it cannot cope with the "%" being seperated from the specifier.  I propose the following:


Macros would be changed to this  (IE the surounding quotes are left off):

#define X8_F  02x  
#define U16_F u    
#define S16_F d    
#define X16_F X    
#define U32_F lu   
#define S32_F ld   
#define X32_F lX   

The macro invocation would look like this  (IE the surounding quotes are left off)::

LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %U16_F\n", port));

This should work on all compilers, I believe, and the resulting code would, of course be the same.

I may have the only compiler that cannot cope with the macros as they are, but its been a pain each time I upgrade to the latest version.  If this change does not cause anyone else problems, I would like to make this change.  I think I still have upload to CVS?

Comments?  Objections?


Best Regards,
Robert Laughlin





reply via email to

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