home bbs files messages ]

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,154 of 243,242   
   Janis Papanagnou to Bart   
   Re: printf and time_t   
   05 Feb 26 23:55:22   
   
   From: janis_papanagnou+ng@hotmail.com   
      
   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.   
      
   Janis   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca