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,158 of 243,242   
   Tim Rentsch to Bart   
   Re: printf and time_t   
   06 Feb 26 02:25:21   
   
   From: tr.17687@z991.linuxsc.com   
      
   Bart  writes:   
      
   > On 04/02/2026 14:22, Tim Rentsch wrote:   
   >   
   >> Bart  writes:   
   >>   
   >>> On 03/02/2026 15:47, Tim Rentsch wrote:   
   >>   
   >> [...]   
   >>   
   >>>> If variable 'u' is declared as uint32_t, a way to print it that is   
   >>>> easy and also type-safe is   
   >>>>   
   >>>>       printf( " u is %lu\n", u+0LU );   
   >>>   
   >>> What about a compound expression of several variables of mixed   
   >>> integer types, possibly even mixed with floats, some of whose types   
   >>> might either be conditional (depending on some macro), or opaque?   
   >>   
   >> What is an example of a conditional/macro-dependent type?   
   >   
   > Example from SDL2:   
   >   
   >   #if defined(_MSC_VER) && (_MSC_VER < 1600)   
   >     ...   
   >     #ifndef _UINTPTR_T_DEFINED   
   >       #ifdef  _WIN64   
   >         typedef unsigned __int64 uintptr_t;   
   >       #else   
   >         typedef unsigned int uintptr_t;   
   >     ...   
   >   
   > Example from SQLITE3:   
   >   
   >   #ifdef SQLITE_OMIT_FLOATING_POINT   
   >   # define double sqlite3_int64   
   >   #endif   
   >   
   >   
   >> Also what sort of opaque types do you have in mind?   
   >   
   > Things like time_t and clock_t, or the equivalent from libraries.   
   >   
   > Yes you could hunt down the exact underlying type (for clock_t in one   
   > case, it was under 6 layers of typedefs and macros), but that would be   
   > for a specific set of headers.   
   >   
   > For system headers, somebody could be using a header with different   
   > definitions.  For user-libraries, it might be a slightly different   
   > version.   
   >   
   >   
   >>  What is the problem you want to solve here?   
   >   
   > The problem is that C expects an exact format-code when trying to use   
   > *printf functions, and for that you need to know the exact types of   
   > the expressions being passed.  For example:   
   >   
   >   uintptr_t x;                    // from above examples   
   >   double y;                       //   
   >   printf("x * y is %?", x * y);   // What's '?'   
      
   I understand.  Thank you for the explanation.   
      
   --- 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