Another printf-type question
rbj at icst-cmr.ARPA
rbj at icst-cmr.ARPA
Wed Jul 16 02:17:18 AEST 1986
Doug Gwyn chastises me:
invprintf(fmt,_0,_1,_2,_3,_4,_5,_6,_7,_8,_9)
is not a portable solution.
I thought I said that. If not, `taint portable', but just might be useful.
In some cases an attempt to invoke
it with a small actual parameter count can even lead to abnormal
process termination.
True, such as floats or doubles, weird format pointers, longs on PDP-11's.
Also, if called directly from main, it could run off the end of the stack.
The reason <varargs.h> or <stdarg.h> exist is to provide the
hooks necessary for implementation of a portable solution;
the other half of the solution requires something like the
v*printf() functions.
I can relate to the v*printf guys.
The fellow asked the great gurus what he *should* have done.
Why do you feed him that garbage in return?
For educational purposes. At least my `solutions' are understandable.
The guy was obviously a novice, and while your solution is probably
the best one, do you think he can read it?
Also, there is no harm in disseminating bad information as well as
good, for comparison purposes, so he can tell the difference. Also,
to understand why yours works, it is useful to know the usual
(or original if you will) calling sequence.
Its probably going to be awhile before he ports code all over creation.
I wish *I* had known the magic printf trick when I wrote code that had to
run in both hosted and standalone 68k environments. I wrote three sets of
code, the common stuff, the hosted interface, and the standalone interface.
We were using only integers (chars, shorts, & ints) & pointers. It would
have been easier and more maintainable if I had rewritten a subset of
printf (no floats, no field widths or left justification, etc)
INSTEAD OF AN ENTIRE INCOMPATIBLE EDITING PACKAGE based on Exec 8!!!
If it's to show us that you don't believe in writing portable
code, we knew that already from your ravings about how the VAX
is the only sane architecture.
Why do you keep saying VAX only? I also mentioned 68k's, ns32032's,
I forgot the PDP-11, all of which I would take home to mother.
I suppose even IBM qualifies as a rational data structure.
Just because a piece of hardware exists doesn't mean it's rational.
Just because a piece of hardware is rational doesn't mean the
software model imposed upon it is rational. INTEL's small, medium,
and large models create more problems than they solve. There is
nothing wrong with the 8086 that treating it like a PDP-11 wouldn't cure.
I suppose I would rather program in C than anything else on a
dinosaur, but I would realize that the model was strained at best.
I will never touch one of those beasts again. As far as I am concerned,
they don't exist. If you want to contort your code to conform to the
lowest common denominator, fine. My code is optimized for sanity.
I am from the National Bureau of Standards, and as such, believe
in them. There ain't nothing else but ASCII. My code will never
support EBCDIC. I expect 'I' + 1 to equal 'J'. If it doesn't,
that's your problem. You fix it.
You say your car is 6 volts, positive ground? Wreck it!
There comes a time to forego the past and desanction it.
If you make it easy for them, they'll never give it up.
Okay, I'm ranting again, let me get back to the subject.
It's all a matter of tradeoffs. Portability comes at a price, both
in time and in space (extra characters), which I find detracts
from readability. Yes, I know that one should aim high, and I do.
Perhaps I aim higher than you. You abide the past, I demand the future.
I added proper cautionary notes. I acknowledged your solution.
In any case, yours is not the only opinion. Mine is shared by
others. We are not unaware of the consequences of our actions,
and accept the responsibility for same. We have made our choice.
Respect it. Agree to disagree.
(Root Boy) Jim Cottrell <rbj at icst-cmr.arpa>
I guess it was all a DREAM.. or an episode of HAWAII FIVE-O...
More information about the Comp.lang.c
mailing list