Go Down

Topic: min, max, abs.. are macroses? (Read 9 times) previous topic - next topic

westfw

Quote
having to learn the basics of templates

I personally would prefer that Arduino NOT become overly full of C++isms.

pYro_65

The only difference to an end user is calling functions where parameters go in '<>' rather than '()', This is incredibly simple even for a novice.

I don't see how the bugs imposed on #defines are a trade off for secure guaranteed execution of a well defined template.
This would save mass amounts of headaches.

C is great but C++ is better*



*this is my own opinion, Moved from C to C++ and never looked back.

Coding Badly

Quote
This only works for gcc as it is a gcc extension. Does anybody use anything else...


Good question.  The Arduino folks are trying to add support for more processor types (like ARM).  There is a possibility that a non-GCC compiler may come into play.

bperrybap



I don't see how the bugs imposed on #defines are a trade off for secure guaranteed execution of a well defined template.
This would save mass amounts of headaches.


I believe that a final solution needs to work for both C and C++

There are no "bugs imposed on #defines"
The existing bugs in the min/max/abs() macros are there because the implementation is too simplistic
and silently generates unintended code.
It is no different than having a bug in your  main line code.
The solution is to simply fix the code.
These simplistic macros started showing up in the early to mid 80s and I've hated them
ever since. They go back to the days before there was much optimization, before function prototypes
and even inline functions and were an attempt to generate faster code.

About macros in general:
there are some things that you can do with macros that cannot be done in any other way.

--- bill

pYro_65

Technically unexpected behaviour is a bug.
Documentation specifying the 'unexpected behaviour' makes it an 'undefined behaviour' and explicitly leaves it to the programmer to investigate, this however is not the case.

Vastly different to having an explicitly defined error in your own code.

However I agree, the solution needs to be workable in C & C++.

that is as easy as a #ifdef  for the C++ define, which leaves reason to provide a safer version when possible.

Go Up