Messages in this thread |  | | | Subject | Re: ntohl and others | | Date | Thu, 16 Oct 1997 01:20:52 -0500 (CDT) | | From | kwrohrer@enteract ... |
| |
And lo, Magnus Ahltorp saith unto me: > Why are ntohl and others defined as macros, and not inlines? (1) As macros, they *are* inline, just not functions. (2) Your desired usage would require a non-inlined instance of the "inline" function to point to. (3) Why on earth do you want the address of ntohl? It's not like you need to change endianness at runtime...
> It's difficult to write: (4) static unsigned long int _HTONL(unsigned long int x){return htonl(x);} if what you propose to do with &htonl really, truly is a good idea.
> #include <asm/byteorder.h> > > int main() > { > unsigned long (*foo)(unsigned long) = htonl; > return (*foo)(17); > } This code is a toy example of using a function pointer, yet tells us nothing about *why* you want to do so...and I really think you don't. What context are you working in, and what other function(s) might you point to besides htonl?
> so, why not: > > static inline unsigned long int htonl(unsigned long int x) { return x; } See (4) above. Note that the function ought not to be declared static if there's any possibility of multiple places forcing the compiler to make an out-of-line copy of the htonl function...(prototype in the header, actual definition in one place only)
Keith
|  |