Discussing with people, asking in interviews, or being asked in interviews, I do not know if I know exactly when to write a function as inline or write it as a macro. Apart from compile-time and run-time consideration, is there any suggestion from coding standard point of view.
I think this is one of those question where it comes to the programmer’s preference, or one may say bias towards the usage. I might be a good idea, if members can quote anecdotes, experiences or situations where they have chosen one over the other.
Macros should be used sparingly, in circumstances where a function will simply not do the job. An example, is error reporting. I use this macro for that purpose:
This has to be a macro in order to get the correct file & line number using the standard
__FILE__and__LINE__macros , and also to provide the error formatting so I can say things like: