[comp.lang.c] Flaming printf

wes@obie.UUCP (Barnacle Wes) (04/25/88)

In article <11154@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes:
% It is not difficult[*] to arrange for the linker to pull in a simple
% printf() if the rest of the program does not use floating point, and a
% full-blown floating point printf if it does.  Just because Microsoft's
% implementation is poor (in terms of space, at any rate) is no reason to
% castigate printf itself.
% 
% -----
% [*]What, never?  Well, hardly ever.  The trick is to have the linker
% examine the undefined externals for floating-point library references,
% and if present, link with `bigprintf.obj'; otherwise it should use
% `littleprintf.obj'.  It is just a Small Matter of Programming.

The Mark Williams C compiler for the Atari ST sort of supports this
idea.  The printf library function does not ordinarily include
floating point routines.  If you specify the -f flag to the compiler,
the larger version of printf (with floating i/o) will be linked
instead.  Not quite as elegant was what Chris proposed, but really
quite functional.
-- 
    /\              -  "Against Stupidity,  -    {backbones}!
   /\/\  .    /\    -  The Gods Themselves  -  utah-cs!uplherc!
  /    \/ \/\/  \   -   Contend in Vain."   -   sp7040!obie!
 / U i n T e c h \  -       Schiller        -        wes

dg@lakart.UUCP (David Goodenough) (04/28/88)

From article <11154@mimsy.UUCP> by chris@mimsy.UUCP (Chris Torek):
>It is not difficult[*] to arrange for the linker to pull in a simple
>printf() if the rest of the program does not use floating point, and a
>full-blown floating point printf if it does.

I agree, and do the same myself. I have LIB.L which is my usual library,
and gets searched whenever I link a program. printf,sprintf,fprintf
all reside here, and link in a normal (i.e. integer only) #doprnt which
actually does the work. All my FP stuff lives in FLIB.L, which is included
in the linkage with a -LF flag (just like UNIX :-). Now FLIB.L ALSO
contains printf,sprintf,fprintf, which also reference (and cause linkage of)
#doprnt, but the #doprnt in FLIB.L knows about floating point, and so
whenever I use printf etc. and link with a -LF, I get the right printf,
and #doprnt. LIB.L is also scanned BUT BECAUSE FLIB.L PROVIDED printf,
IT IS NO LONGER UNDEFINED, SO IT GETS BYPASSED.

Anyone who produces a linker that cannot do what I've just described needs
to talk to his analysts (both system and psycho :-)
--
	dg@lakart.UUCP - David Goodenough		+---+
							| +-+-+
	....... !harvard!adelie!cfisun!lakart!dg	+-+-+ |
						  	  +---+