News for hackers. Stuff that matters.
Re:How to properly use macros in C by loup-vaillant on Sunday December 10, 2017 @04:54PM (#15893694)
> macros can’t be debugged. When you use a function, that function can be stepped through by the debugger. The macro cannot.

Looks like the debugger could use some improvement.

> A macro is faster than a function.

This is false. Macros may be faster in some cases, but I've seen them being slower. I suspect this is because functions have more type information that can help the optimiser. I've tried it with Monocypher: replacing serialisation/de-serialisation functions (load and store) by equivalent macros slowed the whole thing down.

Re:How to properly use macros in C by manwe150 on Sunday December 10, 2017 @11:09PM (#15895104)
> Looks like the debugger could use some improvement.

Try `gcc -g3` (the default is 2). But because C-style macros are context-sensative string operations, the result is not necessarily especially pleasant/useful and can be rather large (slowing down the debugger for everything else).

I find that using `static inline` functions and `static const` variables in the header can just be much nicer to work with all around (some argument type-checking, better stack frame management means alloca is usable, no accidental syntax clashes requiring lots of extra parens to avoid, and real debug info). And, if necessary, use a tiny macro just to form the call to the real function or form the declarations for repeated tabular data. I wouldn't have expected macros to be slower in any case, however.

Re:How to properly use macros in C by loup-vaillant on Monday December 11, 2017 @03:24AM (#15895799)
> I wouldn't have expected macros to be slower in any case, however.

Neither did I to be honest. I was searching for low hanging fruits, and forcing inlining with macros looked made some kind of sense. I expected the compiler to generate the same code, yet somehow it didn't.

Re:How to properly use macros in C by dangerbird2 on Sunday December 10, 2017 @05:27PM (#15893830)
Also, C99 `inline` functions calls do not neccessarily compile to inlined code, and non-inline functions may or may not be inlined, and in certain cases (most notably tail-call optimizations), will not create new stack frames.