From: George Koehler Subject: Re: Cruft: drop htonl() etc. from libc To: Mark Kettenis Cc: Christian Weisgerber , tech@openbsd.org Date: Fri, 12 Apr 2024 16:39:46 -0400 On Fri, 12 Apr 2024 07:17:09 +0200 Mark Kettenis wrote: > There are all kinds of subtleties with inline functions, but in > general you'll need to provide a non-inline implementation as well in > case someone tries to take the address of the function. htonl(3) is a macro, so I can't take its address. exam.c:7:18: error: use of undeclared identifier 'htonl' printf("%p\n", &htonl); If I implicitly declare htonl as a function, then I can take its address. (Avoid which pulls in our htonl macro.) $ cat exam.c int printf(const char *, ...); int main(void) { printf("0x%lx\n", (unsigned long)htonl(0xa1b2c3d4)); printf("%p\n", &htonl); } $ make exam cc -O2 -pipe -o exam exam.c exam.c:5:35: warning: call to undeclared function 'htonl'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] printf("0x%lx\n", (unsigned long)htonl(0xa1b2c3d4)); ^ 1 warning generated. $ ./exam 0xa1b2c3d4 0xc0eb59e8 This was with an unmodified libc, because I have not yet applied the diff. I believe that macros like htonl don't need functions, but this diff is correct to keep a function which already exists.