Okay, first of all, the code I pulled this from is 100% C (C99, which does include inline), don't know why you assumed I was using C++. Second, unlike what some people tried to jam down my throat, inlines are NOT as general as macros. Don't use macros if you don't want to, chances are you'll only be using them for things in which inlines ARE better. I use macros because they can generate anything you want. I build functions out of macros. I access the same set of variables across macros. I use the C preprocessor's name pasting, IE:
Code:
#define arm_access_memory(access_type, direction, adjust_op, mem_type, \
offset_type) \
{ \
arm_data_trans_##offset_type(adjust_op, direction); \
arm_access_memory_##access_type(mem_type); \
} \
Personally, macros have never given me a hard time in terms of the popular caveats (not type safe, don't require actual arguments, multiple evaluation). I'm a low level programmer, I see through things like this easily. The only headaches they've given me is that in C they're not truly multi-line and they're much harder to debug (or sometimes, even get to compile).
Summary: macros are not obsolete if you use C or C++ because inline functions can't accomplish the same thing. And anyone who tells you that what I do is "undefined" by the standard or some garbage like that is full of it.
Here's another example to illustrate the usefulness of macros:
Code:
// These must be statically declared arrays (ie, global or on the stack,
// not dynamically allocated on the heap)
#defile file_read_array(filename_tag, array)
file_read(filename_tag, array, sizeof(array))
#define file_write_array(filename_tag, array)
file_write(filename_tag, array, sizeof(array))
Even though this is restricted (and in such a way that if you use it incorrectly it'll mess up your program rather than give you an error) it is something that as far as I'm aware you simply cannot do with inline functions at all. This pretty much characterizes macros in general: they're more powerful and can save you a lot of typing compared to inlines (where you have to at least pass variables around, in C by address (there's no pass by reference in C) and you're restricted by type) but are more dangerous, so should only be used when the person really knows what they're doing. So a lot of teachers will tell their C/C++ students to use inlines because said students DON'T know what they're doing, or because the teachers learned it that way themselves and don't know any better.
This is what tends to happen in general with programming, how "safe" something is determines whether or not it should be used, regardless of its power. I think that should be left to the programmer's discretion, and it shouldn't simply be assumed that problems like the common ones with macros will catch EVERY programmer (I've heard statements like this before. I've used macros very extensively and have never been caught in any of the typical traps except for a precedence mistake, after which I learned my lesson pretty completely).
Macros also have the benefit of being easy to expand at compile time, if you want to see what the actual generated code looks like. This can be useful for finding some hidden performance killers you missed.