Re:C will never stop you from making mistakes
by blovescoffee on Monday August 10, 2020 @12:11PM
(#24110791)
Is the problem the use of a macro, which isn't as robust as a template, or is there a problem with the macro? All I can figure is there could be an accidental dereference instead of multiply.
[ Parent
| on HN ]
Re:C will never stop you from making mistakes
by virtue3 on Monday August 10, 2020 @12:21PM
(#24110916)
The problem is macro expansion is not (potentially) what you think it is:
MULTIPLY(2+3,4+5) that expands in
2+34+5 (and not into: (2+3)(4+5)).
To have the latter, you should define:
#define MULTIPLY(a,b) ((a)*(b))
https://stackoverflow.com/questions/14041453/why-are-preproc....