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,141 of 243,242   
   Bart to Michael S   
   Re: printf and time_t   
   04 Feb 26 23:24:49   
   
   From: bc@freeuk.com   
      
   On 04/02/2026 20:57, Michael S wrote:   
   > On Wed, 4 Feb 2026 18:11:34 +0000   
   > Bart  wrote:   
   >   
   >> On 04/02/2026 17:12, David Brown wrote:   
   >>   
   >>   > and you want to post about how   
   >>   > terrible C is and how great your own language is?   
   >>   
   >> I think pretty much every language except C seems to have solved this.   
   >>   
   >>   
   >   
   > How do you do it in Fortran?   
   > Also, there are many languages that "solved" it at very high cost of   
   > primitivity of their formatting features. E.g. Pascal.   
   > I don't remember where Ada stands in this picturee. In case of Ada95 or   
   > newer, more like don't know rather then don't remember.   
   >   
      
   Printing expressions involves two kinds of info other than their values:   
      
   (1) The types of the values being printed   
   (2) The desired layout and appearance   
      
   (1) Is always known by the language/compiler/interpreter   
   (2) Is optional when sensible defaults are used   
      
   C's printf scheme always needs both (1) and (2).   
      
   Some languages that have adopted C's printf scheme still need (1), but   
   two I've just tried (Go and OCaml) will report a runtime error if there   
   is a mismatch.   
      
   FORTRAN IV probably had more primitive I/O than C. Ada is also   
   long-winded: you need to call some type-specific function, but it will   
   at least be on top of the types too.   
      
   Some languages get it right, so that (1) is not needed. Examples from   
   old languages include the Algols, Pascal and BASIC. This is where you   
   just do the equivalent of:   
      
      print x   
      
   in whatever syntax is required. A selection of modern languages where   
   you don't need that (1) type info is:   
      
     Lua, Python, Julia, Rust, Nim, Odin, JavaScript, Zig (types optional)   
      
   With C, I don't have a particular problem with the layout features,   
   other than you /always/ have to provide a format string even with   
   throwaway code.   
      
   The problem is working out and maintaining the format codes, and not   
   having compile-time checks unless you use a big, slow compiler with the   
   correct warnings enabled.   
      
   Some languages are worse however, despite not needing type codes; this   
   is Zig, although usually, you'd use an alias for the first part:   
      
      @import("std").debug.print("{} {}\n", .{i, x});   
      
   The C equivalent is this (when i is i32 and x is f64):   
      
      printf("%d %d\n", i, x);   
      
   Suddenly C doesn't look so bad!   
      
   (I just noticed that the second %d should have been %f, but decided to   
   leave it: THIS is the problem.)   
      
   --- 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