Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
GCC: why cannot compile clean printf("%f\n", f16) under -std=c11 -Wall?

Sample code:

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

#ifdef FLT16_MAX
_Float16 f16;
int main(void)
{
    printf("%f\n", f16);
    return 0;
}
#endif

Invocation:

# gcc trunk on linux on x86_64
$ gcc t0.c -std=c11 -Wall

Expected diagnostics:

<nothing>

Actual diagnostics:

t0.c:9:14: warning: format '%f' expects argument of type 'double', but argument 2 has type '_Float16' [-Wformat=]
    9 |     printf("%f\n", f16);
      |             ~^     ~~~
      |              |     |
      |              |     _Float16
      |              double

Does it mean that under __STDC_WANT_IEC_60559_TYPES_EXT__ AND if FLT16_MAX defined the gcc is unaware that printf may be used with _Float16? Should it be aware?

Also: printf("%f\n", f); when f is a float leads to no warning above despite the fact that format '%f' expects argument of type 'double', but argument 2 has type 'float'. Confused.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

From the clang manual:

Because default argument promotion only applies to the standard floating-point types, _Float16 values are not promoted to double when passed as variadic or untyped arguments. As a consequence, some caution must be taken when using certain library facilities with _Float16; for example, there is no printf format specifier for _Float16, and (unlike float) it will not be implicitly promoted to double when passed to printf, so the programmer must explicitly cast it to double before using it with an %f or similar specifier.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!