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 242,925 of 243,242   
   David Brown to Michael S   
   Re: printf and time_t   
   09 Jan 26 09:25:16   
   
   From: david.brown@hesbynett.no   
      
   On 08/01/2026 01:38, Michael S wrote:   
   >   
   > No, it is correct on all implementation. Idea that in C, as opposed to   
   > C++, two unsigned integer types of the same size are somehow   
   > different is, IMHO, an abomination. And that is one not especially   
   > common case in which I don't care about opinion of the Standard.   
   >   
   You can have the opinion that any two integer types of the same size   
   /should/ be fully interchangeable in C.  That's a reasonable opinion,   
   and you are not the only one to think that way.   
      
   But the C language is defined differently.  There are a number of   
   situations where different integer types have the same size (and range   
   and representation), yet are different types.  On most 32-bit platforms,   
   "long" is the same size as either "int" or "long long".  But it is not   
   type-compatible with either.  "uint32_t" will probably be an alias for   
   either "unsigned int" or "unsigned long" (but could on some platforms be   
   an alias for "unsigned char", "char", "unsigned short", or an extended   
   integer type).   
      
   It does not really matter if you think the C language works the way you   
   would like it to - when you program in C, the C standard is the contract   
   between you and the compiler.  We all have aspects of C that we dislike,   
   and I am sure the same applies to compiler writers, but we all agree to   
   stick to a common definition of the language.  If you try to code in   
   some C-like language that works the way /you/ would like it to, you will   
   run into trouble when the compiler interprets your code differently from   
   how you had intended.   
      
   Use the types as the standard specifies.  If the standard says "use %lu   
   for this type, and %u for that type", then do that.  If the standard   
   says "pointers to unsigned int are incompatible with pointers to   
   unsigned long, even if the integer types are the same size", then don't   
   mix such pointer types.  It's not that hard.  Yes, occasionally it can   
   be a little inconvenient or "ugly", but writing correct code pays off.   
      
   --- 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