Issue
My code is below,
namespace A
{
namespace B
{
unsigned int htonl(unsigned int address)
{
return 0;
}
}
}
Now I know that htonl
is a library function in Linux. Even though I am defining it under namespaces it produces the mentioned error. How can I fix it without changing the function signature?
Solution
The problem here is that htonl
, in Linux at least, is a (sometimes) macro that expands to __bswap32
, which in turn is a rather long macro (which has __attribute__((extension))
as part of it). Macros do not "care" about namespaces.
If you REALLY want your own function that is called htonl
(you probably do not, in general - call it something else), then you can do
#ifdef htonl
#undef htonl
#endif
The #ifdef
is there to avoid undefining something that isn't a macro.
Or you could figure out which header file it is that produces htonl
(<arpa/inet.h>
in my Linux installation) and not include that in your code.
Answered By - Mats Petersson Answer Checked By - Mary Flores (WPSolving Volunteer)