Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c    |    Meh, in C you gotta define EVERYTHING    |    243,242 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 243,156 of 243,242    |
|    Bart to Janis Papanagnou    |
|    Re: printf and time_t    |
|    05 Feb 26 23:42:06    |
   
   From: bc@freeuk.com   
      
   On 05/02/2026 22:55, Janis Papanagnou wrote:   
   > On 2026-02-05 18:42, Bart wrote:   
   >> On 05/02/2026 11:41, David Brown wrote:   
   >>>   
   >>> No, the /compiler/ has to work it out. Whether /you/ need to work it   
   >>> out or not, depends on what you are doing with the result.   
   >>   
   >> The compiler will not tell you the format codes to use!   
   >   
   > Well, it seems the compiler I have here does it quite verbosely...   
   >   
   >   
   > $ cc -o prtfmt prtfmt.c   
   > prtfmt.c: In function ‘main’:   
   > prtfmt.c:8:19: warning: format ‘%d’ expects argument of type ‘int’,   
   but   
   > argument 2 has type ‘double’ [-Wformat=]   
   > 8 | printf ("%d\n", f);   
   > | ~^ ~   
   > | | |   
   > | int double   
   > | %f   
   > prtfmt.c:9:19: warning: format ‘%f’ expects argument of type   
   ‘double’,   
   > but argument 2 has type ‘int’ [-Wformat=]   
   > 9 | printf ("%f\n", i);   
   > | ~^ ~   
   > | | |   
   > | | int   
   > | double   
   > | %d   
   >   
   >   
   > ...giving information of every kind - here for two basic types, but   
   > it has also the same verbose diagnostics with the '_t' types I tried   
   > (e.g. suggesting '%ld' for a 'time_t' argument).   
   >   
   > Note: I'm still acknowledging the unfortunate type/formatter-coupling   
   > notwithstanding.   
      
   /Some/ compilers with /some/ options will /sometimes/ tell you when   
   you've got it wrong.   
      
   But you first have to make an educated guess, or put in some dummy   
   format code.   
      
   Eventually, it will compile. Until someone else builds your program,   
   using a slightly different set of headers where certain types are   
   defined, and then it might either give compiler messages that they have   
   to fix, or it show wrong results.   
      
   If I compile this code with 'gcc -Wall -Wextra -Wpedantic':   
      
    #include
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca