lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Print Macros


From: Roger Cover
Subject: Re: [lwip-users] Print Macros
Date: Wed, 13 Apr 2011 16:17:16 -0700

Greetings List,
 
My compiler does not substitute macros inside quotes. The proposed change would not work for me at all, since the example in the original message would result in a final string of "tcp_bind: bind to port %U16_F\n".

Regards,
Roger


From: address@hidden [mailto:address@hidden On Behalf Of Robert
Sent: Wednesday, April 13, 2011 3:41 PM
To: Mailing list for lwIP users
Subject: [lwip-users] Print Macros

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 substitution, 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 separate strings 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 separated from the specifier.  I propose the following:


Macros would be changed to this  (IE the surrounding 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 surrounding 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.

Comments?  Objections?


Best Regards,
Robert Laughlin





reply via email to

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