README.TYPE 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. .\" use -ms
  2. .LP
  3. There were two flavors of changes made to structures in gis.h
  4. and to calls to routines in the library:
  5. .IP 1.
  6. Variables in structures, parameters in argument lists to library routines,
  7. and return values from library routines that really represented
  8. CELL data but were declared as int have been changed to CELL.
  9. The following structures were changed:
  10. .DS
  11. Categories [gis.h]
  12. Cell_stats
  13. Colors
  14. Histogram
  15. Range
  16. Reclass
  17. .DE
  18. The argument type for some parameters for the following routines was changed:
  19. .DS
  20. G_init_cats [cats.c]
  21. G_get_cats
  22. G_set_cats
  23. G_get_color [color.c]
  24. G_set_color
  25. G_make_random_colors [make_colr2.c]
  26. G_make_color_wave
  27. G_make_grey_scale
  28. G_make_color_ramp
  29. G_make_aspect_colors
  30. G_add_histogram [histogram.c]
  31. G_set_histogram
  32. G_update_range [range.c]
  33. .DE
  34. The return value for the following routines was changed:
  35. .DS
  36. G_number_of_cats [cats.c]
  37. G_get_histogram_cat [histogram.c]
  38. .DE
  39. This change does not, at present, require changes to existing code since
  40. the CELL type is currently defined as int.
  41. In the future, if we (or someone else) want to
  42. redefine CELL to long (say on a 16 bit machine), the application code
  43. will compile ok, but will not run correctly since the calling seqences
  44. (including printf and scanf) will not match anymore.
  45. To upgrade GRASS code for this is a big deal.
  46. It consists of
  47. finding all places that ints are used in assignments with
  48. CELL variables,
  49. modifying all the calls to the above routines,
  50. and modifying all calls to other routines that don't know about the CELL
  51. type (in particular printf, scanf, and Vask code).
  52. The way to handle printf for CELL data is to use %ld and cast the
  53. CELL value to long:
  54. .DS
  55. CELL x
  56. printf ("%ld", (long) x);
  57. .DE
  58. The way to handle scanf for CELL data is to use %ld into a long
  59. and assign to the CELL variable:
  60. .DS
  61. CELL x;
  62. long t;
  63. scanf ("%ld", &t);
  64. x = (CELL) t;
  65. .DE
  66. For Vask calls, assign the CELL value to a long, call Vask will the long,
  67. then assign the long to the CELL variable:
  68. .DS
  69. CELL x;
  70. long t;
  71. t = x;
  72. V_clear();
  73. V_ques (&t, 'l', ...);
  74. V_call();
  75. x = t;
  76. .DE
  77. The long vs int issue for CELL also presents a subtle, but
  78. potentially fatal, problem with malloc(n) which requires n to be int.
  79. Suppose we want to allocate an array for reclass, from
  80. cats min to max. What we do now is
  81. .DS
  82. char *table;
  83. CELL min,max;
  84. int len;
  85. len = max - min + 1;
  86. table = malloc (len);
  87. .DE
  88. This will fail if CELL is long and the expression max-min+1 yields
  89. a value which overflows an int. Therefore, we should do
  90. .DS
  91. long len;
  92. len = max - min + 1;
  93. if (len != (int)len)
  94. error("Too many categories");
  95. table = malloc ((int)len);
  96. .DE
  97. .IP 2.
  98. Variables in structures, parameters in argument lists to library routines,
  99. and return values from library routines that should have been long
  100. but were declared as int have been changed to long.
  101. The following structures were changed:
  102. .DS
  103. Cell_stats [gis.h]
  104. Histogram
  105. .DE
  106. The argument type for some parameters for the following routines was changed:
  107. .DS
  108. G_add_histogram [histogram.c]
  109. G_set_histogram
  110. G_find_cell_stat [cell_stats.c]
  111. G_next_cell_stat
  112. .DE
  113. The return value for the following routines was changed:
  114. .DS
  115. G_get_histogram_count [histogram.c]
  116. .DE
  117. These changes required immediate upgrade.
  118. I think this update is done, but I want to review it again.