home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / PROBLEMS.TXT < prev    next >
Text File  |  1997-07-05  |  10KB  |  361 lines

  1. +++Date last modified: 05-Jul-1997
  2.  
  3. === Portability problems and how to solve some of them ====================
  4.  
  5. Contents
  6.  
  7. - Introduction
  8. - Problems with using the ANSI/ISO standard
  9. - Adaptations for specific compilers
  10.   - Turbo C v1.00 (1987)
  11.   - Turbo C v1.50 (1987)
  12.   - Turbo C v2.00
  13. - Some portability notes on specific compilers
  14.   - Turbo C v1.00 (1987)
  15.   - Turbo C v1.50 (1987)
  16.   - Turbo C v2.00
  17.  
  18. Introduction
  19.  
  20. When you get sources from someone else, or give sources to someone else,
  21. you would prefer them to compile without problems and to work right.
  22. Regrettably that is not always entirely possible, but there are a great
  23. many things that can be done to make it so. Essentially those many thing
  24. fall into three groups:
  25. - Using the ANSI/ISO standard.
  26. - Using portability #defines for things not addressed by the standard but
  27.   still common among compilers and operating environments, and Public
  28.   Domain sources for less common items. Both of which can often -- if not
  29.   always -- be found in Snippets.
  30. - Using good coding standards. A good example is contained in the file
  31.   C_port.txt. I use most of the items mentioned in C_port.txt. I only
  32.   disagree with one -- the one about using sizeof -- and I have never found
  33.   problems with indenting pre-processor directives to be any problem.
  34.  
  35.  
  36. Problems with using the ANSI/ISO standard
  37.  
  38. Current compilers -- at least for the PC -- have nearly no problems with
  39. the standard. But older compilers sometimes have severe problems with the
  40. standard.
  41. Turbo C v1.5, which I still use often even though I also have a better
  42. compiler, has problems with multiple inclusion of its own .h files and with
  43. missing items. So I created a simple utility, SAFEMINX, to created
  44. 'wrappers' for each include file. I could have edited the original .h
  45. files, but this way makes it possible to easily revert to the original
  46. state. Then I:
  47. - renamed TC's include directory to d:\turboc\_include
  48. - created a new directory with the old name
  49. - ran SAFEMINX
  50. - and edited four of the new files.
  51.  
  52. During testing of a Snippets beta release this reduced the number of
  53. reported errors (compiling all .C files) from over a thousand to only
  54. thirty four! As the four manually edited files -- or rather its contents --
  55. may be of interest to other users of TC1.5 (and probably the even older TC1
  56. too) I include them here. Separated by a line with hyphens.
  57.  
  58. /*  STDIO.H
  59.     Prevention of double inclusions.
  60. */
  61.  
  62. #ifndef SAFE__STDIO_H
  63. #define SAFE__STDIO_H
  64.  
  65. #include <d:\turboc\_include\STDIO.H>    /* 'original' */
  66.  
  67. #ifndef FILENAME_MAX
  68.   #define FILENAME_MAX  80
  69. #endif
  70. #ifndef FOPEN_MAX
  71.   #define FOPEN_MAX     OPEN_MAX
  72. #endif
  73.  
  74. #endif
  75. ------------------------
  76. /*  SIGNAL.H
  77.     Prevention of double inclusions.
  78. */
  79.  
  80. #ifndef SAFE__SIGNAL_H
  81. #define SAFE__SIGNAL_H
  82.  
  83. #include <d:\turboc\_include\SIGNAL.H>    /* 'original' */
  84.  
  85. #define signal ssignal
  86.  
  87. #endif
  88. ------------------------
  89. /*  ASSERT.H
  90.     Prevention of double inclusions.
  91. */
  92.  
  93. #ifndef SAFE__ASSERT_H
  94. #define SAFE__ASSERT_H
  95.  
  96. #include <d:\turboc\_include\ASSERT.H>    /* 'original' */
  97.  
  98. #include <stdlib.h> /* for abort() */
  99. #include <stdio.h>  /* for fprintf() and stderr */
  100.  
  101. #endif
  102. ------------------------
  103. /*  TIME.H
  104.     Prevention of double inclusions.
  105. */
  106.  
  107. #ifndef SAFE__TIME_H
  108. #define SAFE__TIME_H
  109.  
  110. #include <d:\turboc\_include\TIME.H>    /* 'original' */
  111.  
  112. typedef long clock_t;
  113. #define clock()         *((clock_t far *)0x0040006cL)
  114. #define CLOCKS_PER_SEC  18.2
  115. #define CLK_TCK         18.2   /* Non-ANSI/ISO but _very_ common. */
  116.  
  117. #ifndef _SIZE_T         /* from string.h */
  118. #define _SIZE_T
  119. typedef unsigned size_t;
  120. #endif
  121.  
  122. /* from Snippets strftime.c: */
  123. size_t strftime(char *s, size_t maxs, const char *f, const struct tm *t);
  124.  
  125. #endif
  126.  
  127. === Adaptations for specific compilers ===================================
  128.  
  129. The following sections contain additions to the indicated files for
  130. specific compilers to make these more compliant with the ANSI/ISO standard.
  131. At the end there are some notes on various compilers which also may be
  132. useful to users of other compilers.
  133.  
  134. You should compile and run SAFEMINX first!
  135.  
  136. Please note that this currently may be incomplete for any file. 
  137.  
  138. --- Turbo C v1.0 (1987) -- Not the C++ version! --------------------------
  139.  
  140. --- ASSERT.H
  141.  
  142. #include <stdlib.h> /* for abort() */
  143. #include <stdio.h>  /* for fprintf() amd stderr */
  144.  
  145.  
  146. --- FLOAT.H
  147.  
  148. #define DBL_EPSILON     2.2204460492503131E-16
  149. /* duplicate of (disabled) following section.
  150.    REQUIRED for some Snippets files           
  151. */
  152.  
  153. #if 0  /* disables this section because I'm not sure about the values */
  154.        /* This is taken from TC1.5                                    */
  155.  
  156. #ifndef TC1_FP_ORIGINAL
  157.  
  158. #undef DBL_MAX_EXP      /* undefine existing values because */
  159. #undef FLT_MAX_EXP      /* they are _very_ probably wrong   */
  160. #undef LDBL_MAX_EXP
  161. #undef DBL_MIN_EXP
  162. #undef FLT_MIN_EXP
  163. #undef LDBL_MIN_EXP
  164.  
  165. #define DBL_MAX_EXP     +1024
  166. #define FLT_MAX_EXP      +128
  167. #define LDBL_MAX_EXP    +1024
  168.  
  169. #define DBL_MIN_EXP     -1021
  170. #define FLT_MIN_EXP      -125
  171. #define LDBL_MIN_EXP    -1021
  172.  
  173. #endif /* TC1_FP_ORIGINAL */
  174.  
  175. #define DBL_DIG         14
  176. #define FLT_DIG          6
  177. #define LDBL_DIG        14
  178.  
  179. #define DBL_MANT_DIG    53
  180. #define FLT_MANT_DIG    24
  181. #define LDBL_MANT_DIG   53
  182.  
  183. #define DBL_EPSILON     2.2204460492503131E-16
  184. #define FLT_EPSILON     1.19209290E-07F
  185. #define LDBL_EPSILON    2.2204460492503131E-16
  186.  
  187. #define DBL_MIN         2.225073858507201E-16
  188. #define FLT_MIN         1.17549435E-38F
  189. #define LDBL_MIN        2.225073858507201E-16
  190.  
  191. #define DBL_MAX         1.797693134862316E+308
  192. #define FLT_MAX         3.40282347E+38F
  193. #define LDBL_MAX        1.797693134862316E+308
  194.  
  195. #define DBL_MAX_10_EXP   +308
  196. #define FLT_MAX_10_EXP    +38
  197. #define LDBL_MAX_10_EXP  +308
  198.  
  199. #define DBL_MIN_10_EXP   -307
  200. #define FLT_MIN_10_EXP    -37
  201. #define LDBL_MIN_10_EXP  -307
  202.  
  203. #endif /* if 0 */
  204.  
  205. --- SIGNAL.H
  206.  
  207. #define signal ssignal
  208.  
  209.  
  210. --- STDIO.H
  211.  
  212. #define FILENAME_MAX  80
  213. #define FOPEN_MAX     OPEN_MAX
  214.  
  215. /* duplicated from dos.h: 
  216.    (required to handle the #define for 'remove')
  217. */
  218. int     _Cdecl unlink(char *filename);
  219.  
  220. /* added for ANSI compliance:
  221.    WARNING: I only did compilation testing. NO functional testing (yet) !!!
  222. */
  223. typedef long fpos_t;
  224. #define fgetpos(stream,pos) ((((*(pos))=ftell(stream))==-1) ? -1 : 0 )
  225. #define fsetpos(stream,pos) fseek(stream,*(pos),SEEK_SET)
  226.  
  227. --- STDLIB.H
  228.  
  229. #define EXIT_SUCCESS  0
  230. #define EXIT_FAILURE  1
  231.  
  232. /* duplicated from stddef.h: */
  233. #ifndef NULL
  234. #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  235. #define NULL    0
  236. #else
  237. #define NULL    0L
  238. #endif
  239. #endif
  240.  
  241. /* Missing entirely. Value according to doc's: */
  242. #define RAND_MAX  0x7FFF
  243.  
  244. --- STRING.H
  245.  
  246. /* duplicated from stddef.h: */
  247. #ifndef NULL
  248. #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  249. #define NULL    0
  250. #else
  251. #define NULL    0L
  252. #endif
  253. #endif
  254.  
  255.  
  256. --- TIME.H
  257.  
  258. typedef long clock_t;
  259. #define clock()         *((clock_t far *)0x0040006cL)
  260. #define CLOCKS_PER_SEC  18.2
  261. #define CLK_TCK         18.2   /* Non-ANSI/ISO but _very_ common. */
  262.  
  263. #ifndef _SIZE_T         /* from string.h */
  264. #define _SIZE_T
  265. typedef unsigned size_t;
  266. #endif
  267.  
  268. /* from Snippets strftime.c: */
  269. size_t strftime(char *s, size_t maxs, const char *f, const struct tm *t);
  270.  
  271. --- Turbo C v1.5 (1987) --------------------------------------------------
  272.  
  273. --- ASSERT.H
  274.  
  275. #include <stdlib.h> /* for abort() */
  276. #include <stdio.h>  /* for fprintf() amd stderr */
  277.  
  278. --- SIGNAL.H
  279.  
  280. #define signal ssignal
  281.  
  282. --- STDIO.H
  283.  
  284. #define FILENAME_MAX  80
  285. #define FOPEN_MAX     OPEN_MAX
  286.  
  287. --- TIME.H
  288.  
  289. typedef long clock_t;
  290. #define clock()         *((clock_t far *)0x0040006cL)
  291. #define CLOCKS_PER_SEC  18.2
  292. #define CLK_TCK         18.2   /* Non-ANSI/ISO but _very_ common. */
  293.  
  294. #ifndef _SIZE_T         /* from string.h */
  295. #define _SIZE_T
  296. typedef unsigned size_t;
  297. #endif
  298.  
  299. /* from Snippets strftime.c: */
  300. size_t strftime(char *s, size_t maxs, const char *f, const struct tm *t);
  301.  
  302.  
  303. --- Turbo C v2.0 ---------------------------------------------------------
  304.  
  305. --- STDIO.H
  306.  
  307. #define FILENAME_MAX  80
  308. #define FOPEN_MAX     OPEN_MAX
  309.  
  310. --- TIME.H
  311.  
  312. #define CLOCKS_PER_SEC CLK_TCK
  313.  
  314. #ifndef _SIZE_T         /* from string.h */
  315. #define _SIZE_T
  316. typedef unsigned size_t;
  317. #endif
  318.  
  319. /* from Snippets strftime.c: */
  320. size_t strftime(char *s, size_t maxs, const char *f, const struct tm *t);
  321.  
  322.  
  323. ==== Some portability notes on specific compilers ========================
  324.  
  325. ---- Turbo C v1.00
  326.  
  327. TC1.0 in not very ANSI/ISO compliant. But most ANSI/ISO items more or less
  328. work correctly. As indicated in the preceding sections there are however
  329. some items missing. In addition to these the following is not there:
  330. - tmpnam() and some associated functions.
  331. - ldiv_t, div_t and associated functions.
  332.  
  333. In addition strerror() is _NOT_ ANSI/ISO compliant.
  334.  
  335. TC1.0 does NOT like items with both 'interrupt' and 'far'.
  336. It also does not have the common (Borland) items:
  337. - random() and randomize()
  338. - chsize()
  339. - gotoxy()
  340. - stdprn and stdaux
  341.  
  342.  
  343. ---- Turbo C v1.50
  344.  
  345.  
  346.  
  347. ---- Turbo C v2.00
  348.  
  349. TC2 considers "#pragma option ..." an error. Enclose these between
  350. "#if defined(__TURBOC__) && __TURBOC__ >0x202" and "#endif".
  351. (For older TC's these #pragma's don't work anyway ...)
  352.  
  353.  
  354. --------------------------------------------------------------------------
  355.  
  356. That's it for the time being. Maybe I'll expand this for the next release
  357. of Snippets. Suggestions and comments are welcome. An overview of what
  358. items the portability files of Snippets deal with could make sense.
  359.  
  360. === A.Reitsma, Delft, The Netherlands. 95-10-30 ====== Public Domain =====
  361.