4

I want to use specific c11 macros in my C code, but they aren't available. I installed gcc 8.4 via pkg_add on a fresh OpenBSD 7.1 install. /usr/include/float.h is missing any c11 definitions.

gcc-8.4:

sunfire$ egcc -std=c11 prog.c
prog.c: In function 'main':
prog.c:5:17: error: 'FLT_DECIMAL_DIG' undeclared (first use in this function); did you mean 'DECIMAL_DIG'?
printf("%d\n", FLT_DECIMAL_DIG);
               ^~~~~~~~~~~~~~~
               DECIMAL_DIG

clang-13.0.0:

sunfire$ clang prog.c -std=c11                                                       
prog.c:5:18: error: use of undeclared identifier 'FLT_DECIMAL_DIG'
        printf("%d \n", FLT_DECIMAL_DIG);
                        ^
1 error generated.

I looked into the FreeBSD headers and they ship with c11 definitions. Is there a reason OpenBSD does not include those definitions?

Update: Code to reproduce:

#include <stdio.h>
#include <float.h>

int main() {
        printf("%d \n", FLT_DECIMAL_DIG);
}

Output on GNU/Linux x86-64 is 9\n

xpkr
  • 41
  • 2
  • Try running `find / float.h` to check if it even exists, maybe the linker doesn't find it because it isn't in `PATH` environment variable. – shahar Sep 02 '22 at 12:47
  • I think the problem is that I installed gcc 8.4 but it still uses the header files from the OpenBSD base system. No idea yet how I can get updated headers. – xpkr Sep 02 '22 at 20:34
  • But does your clang find a `float.h` with `FLT_DECIMAL_DIG` support? Not sure what I am doing wrong. Fresh OpenBSD 7.1 install. No c11 compatible `float.h` can be found on the whole system, neither gcc 8.4 (from pkg_add) nor clang (from system) ship c11 compatible `float.h` headers. Both support -std=c11. – xpkr Sep 03 '22 at 07:30
  • 2
    Apparently, gcc-8.4 - when build from ports - ships its own c11 compatible `float.h` in `/usr/local/lib/gcc/x86_64-unkown-openbsd7.1/8.4.0/include`. No idea why this does not apply to the pkg_add version. – xpkr Sep 03 '22 at 09:51

0 Answers0