On Thu, 2009-05-21 at 22:38 -0400, Duane Ellis wrote:
> Zach>
> > static inline functions should be preferred over macros, yes.
> >   
> I personally despise 'static inline' functions.
> 
> One cannot never set breakpoints on them, because the debugger cannot 
> figure out *which* instance you want to set the breakpoint at.

That is true of a call to any small well-used function (not just inline
ones), so I'm not sure that I understand your point.  Certainly, I am
not sure how the other alternatives really make debugging all that much
easier or better.  If anything, macros are more dangerous.

The first Google result for 'static inline or macros' gave me the
following page, which I think makes the argument fairly clear:

        
https://www.securecoding.cert.org/confluence/display/seccode/PRE00-C.+Prefer+inline+or+static+functions+to+function-like+macros

As this shows, programmers that always expect macros to work like
functions are in for a huge surprise when using a macro like this:

        #define CUBE(n) ((n) * (n) * (n))
        ...
        y = CUBE(x++);

but the same invocation would have worked fine with a function:

        static inline cube(int n) { return n * n * n; }
        ...
        y = cube(x++);

Honestly, I would prefer to read the second one, and debugging it will
be easier because programmers will not need to worry about these kinds
of side-effects occurring.  

Bottom line: static inline functions should be preferred over macros in
all new C99 code.

Cheers,

Zach

P.S. Debuggers are for wimps. ;)

_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to