lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Print Macros


From: David Empson
Subject: Re: [lwip-users] Print Macros
Date: Thu, 14 Apr 2011 10:58:01 +1200


The way that LWIP implements these macros is consistent with ANSI C-1990 (or later revisions) and how it defines concatenation of strings. Your compiler is not compliant with ANSI C if it cannot handle this. (See section 6.1.4 of ANSI C-1990, subsection "Semantics", with reference to earlier sections that define the translation phases.)
 
Your proposed solution of dropping the quotes and embedding the macro name within the string will not work with any ANSI C compiler, since the macro name would be regarded as literal text in that context. It would therefore break LWIP debug macros for everyone else.
 
----- Original Message -----
From: Robert
Sent: Thursday, April 14, 2011 10:41 AM
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]