2

I'm rewriting some Mac code that embeds a freeware library originally written in C. The compiler is complaining that since I'm using long double, I should use fabsl rather than fabs. So I went and changed them.

However, reading a few pages on the topic it seems that there should be no difference, that ever since C99, there is a type generic macro that inserts the correct call based on type.

So perhaps I am using the wrong dialect?

Does anyone know what the Compiler Default is in xcode7, and whether it has the generic macro?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98

1 Answers1

2

The generic macro is defined in <tgmath.h>, so you need to #include it, as shown in the following snippet:

#include <tgmath.h>
#include <stdio.h>

int main() {
  long double ld = 3.14;
  double d = 3.14;
  float f = 3.14f;
  printf("%Lf %lf, %f\n",fabs(ld), fabs(d), fabs(f));
  return 0;
}

It compiles flawlessly with

gcc -Wall -Wextra a.c -oa -std=c99
serge-sans-paille
  • 2,109
  • 11
  • 9