Thanks!! This is very helpful!

The hope is to generate the same C99 code regardless of the platform. So we
need to use a math library that will work across platforms and deliver
consistent behaviour.

Ivan

On Fri, Apr 22, 2022 at 5:22 AM David Brown <david.br...@hesbynett.no>
wrote:

> On 22/04/2022 02:18, Ivan Perez wrote:
> > Hi,
> >
> > I'm trying to compile a program for arduino that relies on tgmath.h to
> > pick the right version of a function based on the types (the code is
> > automatically generated by another tool).
> >
> > It's failing to compile with avr because tgmath.h is missing.
> >
> > I thought it was part of the standard C distribution since C99 and thus
> > I'd be able to rely on it, but I'm no C expert. Does anyone know why it
> > is not included in avr-libc? Any advice?
> >
> > I'm on Ubuntu 20.04, using:
> > avr-libc 2.0.0+Atmel3.6.2-1.1
> > gcc-avr 5.4.0+Atmel3.6.2-1
> > binutils-avr 2.26.20160125+Atmel-3.6.2-2
> >
> > Thanks,
> >
> > Ivan
>
> You are right that <tgmath.h> has been part of C since C99.  But it is
> not part of C++, which is what the Arduino tools use.  <tgmath.h> has
> macros for type-generic maths functions, and was originally implemented
> with compiler-specific extensions.  With C11, the "_Generic" feature can
> be used to make compiler-independent implementations of the functions.
> In C++, function overloading has existed from the beginning, and is done
> in a completely different way.  (Indeed, <tgmath.h> in C was invented to
> give C programmers the convenience C++ users already enjoyed for their
> maths functions, but made in a C-style manner.)
>
> So for your C++ code, you should use <cmath>, not <tgmath.h>, and
> otherwise the usage will be the same.  (You might need a "using
> namespace std;", but the Arduino IDE likes to confusingly hide such
> detail.)
>

Reply via email to