Page 1 of 1

lwip macro name clashes

Posted: Wed Aug 16, 2017 8:20 pm
by permal
Hi,

I think I've seen this issued discussed briefly either here on the forum or on GitHub, but I can't find the post now so I'll ask again.

lwip defines a lot of macros with very general names such as connect, bind, send etc. in socket.h. These macros gives quite a few headaches since they clash with other code, both in the standard library and my own.

To handle these I've had to be very careful in what order files are included, but also do dirty tricks such as this:

Code: Select all

#undef write
#undef read
#undef bind
By changing the macros to inline functions these issues can be avoided with no additional overhead..

So by turning this

Code: Select all

#define read(s,mem,len)                           lwip_read_r(s,mem,len)
#define write(s,dataptr,len)                      lwip_write_r(s,dataptr,len)
into this

Code: Select all

inline int read(int s,void* mem, size_t len) {return  lwip_read_r(s,mem,len);}
inline int write(int s,const void* dataptr, size_t len) {return  lwip_write_r(s,dataptr,len); }
I believe a lot of us will be happier when using ESP-IDF with this change.

Thoughts? Comments?

Would this be welcome as a PR?

Re: lwip macro name clashes

Posted: Thu Aug 17, 2017 1:00 am
by kolban
Might this be related to this issue?

https://github.com/espressif/esp-idf/pull/586

Re: lwip macro name clashes

Posted: Thu Aug 17, 2017 5:16 am
by permal
kolban wrote:Might this be related to this issue?

https://github.com/espressif/esp-idf/pull/586
Yes, and this too: https://github.com/espressif/esp-idf/issues/273