Subject: Re: printf formats again
To: None <current-users@NetBSD.ORG>
From: Greg A. Woods <email@example.com>
Date: 11/18/1996 17:27:15
[ On Sun, November 17, 1996 at 19:49:10 (-0500), Chris G. Demetriou wrote: ]
> Subject: Re: printf formats again
> > Maybe, but I'd personally far prefer something like
> > printf("%B*", sizeof(off_t), (off_t) foo);
> > This should solve the problem for user-supplied types too.
> I like this idea, a lot better than anything that involves having
> printf parse the strings looking for type names and then switching
> based on the type. That's just too inflexible.
I meant to say "%*B" of course, but you get/got the idea! Since type
sizes are likely to change between platforms, and possibly even between
compilers, I don't see any other solution but to provide the size at
runtime. I sure as heck don't want to assume the standard library
routines are really going to do the type-name parsing, even if they can.
> It'd sort of be nice to have a way to hard-code the size in the format
> string, so you wouldn't need to have to pass it as an argument, but
> hey, this'd be pretty good.
Hard-coding the size is what we have now, except for this super-silly
idea of "long long", and in all cases but "long long" a cast to a known
basic integer type can be certain to work. Of course for this to be
generally useful we'd have to always assume the largest possible integer
size for all "custom" types such as off_t and time_t. This isn't very
Of course one can take the "%*" idea quite some distance, including
providing alternate format specifiers for other styles of output, such
as octal (%O), hex (%X or maybe %H to avoid other conflicts), decimal
(%D), binary (%B), etc.
Since C (at least these days) is primarily an octet based language, I
think we can survive with %*B and sizeof() to calculate the value,
though in some ways I'd rather see it specified in number of "int"
chunks to make natural type promotion easer to deal with! ;-)
Greg A. Woods
+1 416 443-1734 VE3TCP robohack!woods
Planix, Inc. <firstname.lastname@example.org>; Secrets Of The Weird <email@example.com>