diff options
| author | Aaron Puchert <aaron.puchert@sap.com> | 2017-11-17 17:46:34 +0100 |
|---|---|---|
| committer | Aaron Puchert <aaronpuchert@alice-dsl.net> | 2017-12-17 23:34:40 +0100 |
| commit | a07501a165e6f2521c9aa13fa63fab33cf67d876 (patch) | |
| tree | 846a2df69948cb6d4927c0c8d5b953786df5cb04 /src/pj_datums.c | |
| parent | 95f8e749e712218ca49e4025fe6ab59ddf991c60 (diff) | |
| download | PROJ-a07501a165e6f2521c9aa13fa63fab33cf67d876.tar.gz PROJ-a07501a165e6f2521c9aa13fa63fab33cf67d876.zip | |
Declare non-local variables as const where possible
Having non-const variables of static lifetime or even global scope is
usually a bad idea. These variables are inherently constants, and this
should be enforced.
This required marking some functions as not modifying input parameters
and marking some pointers as pointers to const.
One advantage is that the compiler usually puts const static variables
in a read-only code segment, so they can't be modified physically.
This can be verified with `nm` (on POSIX systems).
To avoid changes to the public API, functions returning non-const
pointers to data tables were left intact, but the returned data may not
be modified. Internally we prefer using the proj_list_* functions over
the pj_get_*_ref functions, because the former return const pointers.
Diffstat (limited to 'src/pj_datums.c')
| -rw-r--r-- | src/pj_datums.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/pj_datums.c b/src/pj_datums.c index c9655cd6..834ce724 100644 --- a/src/pj_datums.c +++ b/src/pj_datums.c @@ -25,8 +25,9 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_DATUMS__ +#include "proj.h" +#define PJ_DATUMS__ #include <projects.h> /* @@ -35,7 +36,7 @@ * datum name for the comments if available. */ -C_NAMESPACE_VAR struct PJ_DATUMS pj_datums[] = { +C_NAMESPACE_VAR const struct PJ_DATUMS pj_datums[] = { /* id definition ellipse comments */ /* -- ---------- ------- -------- */ {"WGS84", "towgs84=0,0,0", "WGS84", ""}, @@ -65,12 +66,11 @@ C_NAMESPACE_VAR struct PJ_DATUMS pj_datums[] = { }; struct PJ_DATUMS *pj_get_datums_ref() - { - return pj_datums; + return (struct PJ_DATUMS *)pj_datums; } -C_NAMESPACE_VAR struct PJ_PRIME_MERIDIANS pj_prime_meridians[] = { +C_NAMESPACE_VAR const struct PJ_PRIME_MERIDIANS pj_prime_meridians[] = { /* id definition */ /* -- ---------- */ {"greenwich", "0dE"}, @@ -90,8 +90,11 @@ C_NAMESPACE_VAR struct PJ_PRIME_MERIDIANS pj_prime_meridians[] = { }; struct PJ_PRIME_MERIDIANS *pj_get_prime_meridians_ref() +{ + return (struct PJ_PRIME_MERIDIANS *)pj_prime_meridians; +} +const PJ_PRIME_MERIDIANS *proj_list_prime_meridians(void) { return pj_prime_meridians; } - |
