Skip to content

Use of macros for math functions causes unexpected results when argument has side effect #85

Open
@iacopobaroncini

Description

@iacopobaroncini

Hi folks,

I know it has been discussed already here and there...

I find semantically wrong the fact that the following math functions are implemented as macros:
abs, min, max, constrain, round... and let me add bitWrite to the list.

It is well known that using these function the way the rest of the world does, introduces faults, and therefore generates failures.

Writing something like abs(cos(x) - 123 * sq(sin(x)) would introduce redundant calculations, just a crazy delay in this case...
Writing something like abs(a += b) or abs(i++) just introduces a fault... it does something different (wrong in fact).

Assuming that using template and inline functions would solve the issue with no extra executable space taken, I would like to know if there is any other good reason why those dangerous
macro definitions are still in force.

Kind regards,
Iacopo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions