lwip macro name clashes
Posted: Wed Aug 16, 2017 8:20 pm
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:
By changing the macros to inline functions these issues can be avoided with no additional overhead..
So by turning this
into this
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?
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
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)
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); }
Thoughts? Comments?
Would this be welcome as a PR?