[lkml]   [1997]   [Oct]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: ntohl and others
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)


 \ /
  Last update: 2005-03-22 13:40    [W:0.025 / U:13.352 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site