-
-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Original issue: HDFFR-622
Note that the C++ part was in HDFFV-3384 and completed.
- Declare all function arguments in the API which are constants to be
const. The C const modifier was added to the language late, probably
after HDF4 development was well underway.
The reason this is useful is that it will make C++ interface better (but
also help C to some degree as well). If a programmer declares a pointer
variable in C or C++ to be a constant (i.e. declaring that the referent
is constant) then he or she must go through contortions to pass it to an
HDF4 function (otherwise it will be rejected by the compiler). For
example, the C++ string objects and associated manipulation routines are
an excellent way to write programs that do string manipulation without
the specter of buffer overruns and the associated segmentation faults.
However, in order use these string objects with HDF4 functions a
character pointer must be available. The C++ string class function
c_str() does this in one step, except that since it returns a constant
pointer to a character string the result must be massaged to be
acceptable to the compiler. Declaring inputs like filenames and objects
names to be constant would solve this. (This might also flush out bugs
in the HDF4 library, where input arguments are mistakenly
modified--though I would be surprised to learn of these errors in such a
mature library.)
- It would be nice if all the macros which are used to represent
constants could be changed to constant variables. This should make them
available to people trying to debug code inside a debugger (without
having to dig up the appropriate include file). I also think (but
haven't verified this) that it would also make the symbols (and their
values) available to software which dynamically loads the HDF libraries.
Generally, these constants represent HDF4 types and return codes.
This change could also be applied to future HDF5 releases as well.