asm/unistd.h
It would seem to me that after hearing how the macros are used in practice, wouldn't turning them into inline functions be an improvement? This is something gcc supports, it accomplishes the same thing, and has the added advantage of type checking.
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC92
Or perhaps type checking macro arguments would be another fertile area for the Stanford Checker...
Cheers,
Steve Grubb
Quoted 8 lines · Steve Grubb
It would seem to me that after hearing how the macros are used in practice, wouldn't turning them into inline functions be an improvement? This is something gcc supports, it accomplishes the same thing, and has the added advantage of type checking.
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC92Or perhaps type checking macro arguments would be another fertile area for the Stanford Checker...
There are benefits to macros too. One that I like for debuggin is that the C parser will unravel a macro within the context of the execution:
#ifdef DEBUG
#define KMALLOC(x,y) \
printk(__FILE__ ":%d: kmalloc(%d,%d")\n", __LINE__,x,y); \
kmalloc(x,y);
#else
#define KMALLOC(x,y) \
kmalloc(x,y);
#endif
I think the benefit of a macro here is quite visible... you cannot do this with an inline.
You may also look at some better reasons:
http://www.uwsg.iu.edu/hypermail/linux/kernel/9810.3/0323.html
[btw I found this by looking for 'macros vs inline' on google/linux]
Bart.
Signature · 1 line
WebSig: http://www.jukie.net/~bart/sig/
Quoted 5 lines · Steve Grubb
It would seem to me that after hearing how the macros are used in practice, wouldn't turning them into inline functions be an improvement? This is something gcc supports, it accomplishes the same thing, and has the added advantage of type checking.
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC92
Two reasons:
1) Sometimes I don't want any type checking because it would create the necessity of adding a new include to a file --> a circular dependency to resolve. Macros hide the types except in the cases where they are actually invoked :-)
2) Historically GCC was very bad with code generation with inline functions, so at that time the GCC manual statement "inline functions are just like a macro" was technically false :-)
Yes, I know this is much different in today's gcc tree, but there hasn't been a gcc release in over 2 years so...
Later,
David S. Miller
[email protected]