home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 6656 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  4.0 KB

  1. Path: easy.in-chemnitz.de!mkmk!floh
  2. From: floh@mkmk.in-chemnitz.de (Andre Weissflog)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: include:clib/stdio_protos.h - where is it?
  5. Message-ID: <wMfky*sI0@mkmk.in-chemnitz.de>
  6. Date: Sat, 30 Mar 1996 13:46:08 CET
  7. Reply-To: floh@mkmk.in-chemnitz.de
  8. References: <354.6656T1088T147@mistral.co.uk> <4iIiy*XH0@mkmk.in-chemnitz.de>
  9.  <1035.6658T1363T2026@mistral.co.uk>
  10. Distribution: world
  11. Organization: private uucp site
  12. X-Newsreader: Arn V 1.04
  13.  
  14. In article <1035.6658T1363T2026@mistral.co.uk>, Adam Atkinson writes:
  15.  
  16. > On 25-Mar-96 19:35:16, Andre Weissflog said:
  17. > >I guess they mean <clib/alib_stdio_protos.h>. I would recommend
  18. > >*not* to use those functions unless you know exactly what you're 
  19. > >doing, instead use the vanilla ANSI-stdio-functions that came
  20. > >with your compiler's c.lib, they are more powerful, and
  21. > >compatible with the rest of the ANSI file io stuff.
  22. > Most people seem to have given me exactly the opposite advice. i.e. don't
  23. > mix ansi and amiga-specific stuff unless there is a good reason to. I'm
  24. > still feeling pretty lost, but my first 2 programs have compiled and work,
  25. > which is something.
  26.  
  27. Uhmm, yes, they are right, and my statement was possibly a bit
  28. too short...
  29.  
  30. ANSI C specifies a few hundred support functions that cover stuff
  31. like file i/o, string manipulation, memory management etc etc 
  32. etc... This is the common programming environment you can expect
  33. from any ANSI compiler on any machine in the galaxy (and possibly
  34. beyond). This programming environment is basically like a
  35. operating system on its own, however this "os" is always built
  36. on top of the native operating system of the machine (with the
  37. exception of elevator controllers maybe).
  38.  
  39. AmigaOS offers hundreds of functions too, also covering stuff
  40. like memory management, file i/o etc...
  41.  
  42. That's the reason why one should not mix ANSI style and AmigaOS
  43. style programming. It's certainly possible to some degree, but 
  44. leads to unreadably code and what you get in the end are all the 
  45. disadvantages of both worlds. One of the few exceptions are 
  46. ANSI C's string manipulation functions, like strcpy(), because 
  47. they have no AmigaOS equivalent.
  48.  
  49. Thus: If you want to be sure your program compiles also on
  50. other systems, do it 100% ANSI C. It's completely fine to
  51. do console based programs that way on the Amiga, where you
  52. can go to the SGI next door and recompile and use it
  53. there without one change.
  54.  
  55. If you want to write a program that makes use of the phantastic
  56. AmigaOS stuff, then go with the AmigaOS's functions as much
  57. as possible (and buy the ROM Kernel Reference Manuals please).
  58.  
  59. Phew... now to alib_stio_protos.h:
  60.  
  61. If you look at that file, you see those prototype definitions:
  62.  
  63.     LONG printf( STRPTR fmt, ... );
  64.     LONG sprintf( STRPTR buffer, STRPTR fmt, ... );
  65.     LONG fclose( long stream );
  66.     LONG fgetc( long stream );
  67.     LONG fprintf( long stream, STRPTR fmt, ... );
  68.     LONG fputc( long c, long stream );
  69.     LONG fputs( UBYTE *s, long stream );
  70.     LONG getchar( void );
  71.     LONG putchar( long c );
  72.     LONG puts( BYTE *s );
  73.  
  74. The names are clearly ANSI C, but the used datatypes are
  75. Amiga style. Those functions are neither clean ANSI C, nor 
  76. AmigaOS. They encapsulate AmigaOS calls, but are "bastards" from 
  77. the outside.
  78.  
  79. Why C= ever created those functions probably only know the
  80. AmigaOS tribal elders. The only advantage one gets from using them
  81. is smaller programs (somewhere around 3..5 KByte smaller because
  82. shared library code is used and several startup initialisations
  83. are not needed). The main disadvantage is you can't mix them
  84. with all the other nice ANSI file i/o functions, because different
  85. file descriptors are used. And you must make sure to link amiga.lib
  86. before c.lib, or the linker will use the c.lib versions anyway.
  87.  
  88. Everything clear now? :-)
  89.  
  90. Bye,
  91. -Floh.
  92.  
  93. ====//=== Andre Weissflog <floh@mkmk.in-chemnitz.de> =======
  94. ...//..........."Spirits in the material world"............
  95. \\//......90% of everything is crap (Sturgeon's Law)......
  96. =\\===============================================Amiga!=
  97.  
  98.