TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: KURT KUZBA
from: HERMAN SCHONFELD
date: 1998-04-27 16:26:00
subject: cprintf() & standards

HS>   And it was mainly for the use of ansi-colours, was it
HS>   not? That is why the c standard doesn't allow printf() to
HS>   output colours
KK>   Actually, that is exactly backwards. :)
KK>   printf() lacks color and cursor control because those things
KK>   do not necessarily exist on the device being programmed, and
KK>   so are not necessary to a standard implementation.
KK>   Heck... my toaster doesn't even have a printer, much less a
KK>   random access type display such as a crt or led screen.
KK>   ( NOTE: This is a theoretical toaster with an embedded
KK>      controller programmed in C. My REAL toaster employs
KK>      springs and levers and a variable mechanical timer,
KK>      and is badly in need of replacement, having lost the
KK>      ability to adequately eject toasted objects and not
KK>      being configured, in hardware, for the acceptance of
KK>      thicker comestibles, such as bagels. )
KK>   cprintf() is a non-standard addition for platform specific
KK>   compilers in which such things may be taken for granted.
KK>   There is a sort of quasi-standard, or general consensus of
KK>   the way things are done within the conio library, but nothing
KK>   is guaranteed by the standard, and it does vary from compiler
KK>   to compiler, sometimes enough to thoroughly vex a programmer
KK>   attempting to change from, say, Turbo C, to MS C.
KK>   The point is, that, beyond the standard, nothing is certain.
KK>   Every compiler producer is at liberty to interpret their
KK>   nonstandard functions in any way they find makes sense to
KK>   them, and will best serve their customers. You can trace the
KK>   logic of the various implementations easily enough, though
KK>   it may give you a bit of a headache. 
KK>   Wherever cross-platform development is an issue, or code is
KK>   to be shared with users of other compilers or OS's, then an
KK>   effort should be made to either adhere to the standard or
KK>   wrap the nonstandard calls in a secondary function, wherein
KK>   the person using the source code may find all the nonstandard
KK>   function calls, along with comments on their use and purpose
KK>   so that they may either replace them or provide their own
KK>   code to produce the same intended results.
Backwards? That's exactly what I said.
Let's re-cap for all those who missed it.
1. printf() fail colour/cursor attributes, it ONLY outputs chars to stdout.
2. cprintf() is identical to printf and has color/cursor attributes
    and can output directly through bios.
3. prinft() is IN the standard, cprintf() isn't.
4. Some compilers don't have cprintf(), however their printf()
    does the colour/cursor formatting automatically.
5. rule 4 is ILLEGAL according to the standard as printf() can
    ONLY output characters, nothing else (i.e. colours)
6. You dont always need to follow the standard, and are extremely
    naeve if you do.
... @N?! What a strange name! ;-)
--- Ezycom V1.48g0 01fd016b
---------------
* Origin: Fox's Lair BBS Bris Aus +61-7-38036821 V34 +Node 1 (3:640/238)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.