NOAA-EMC / NCEPLIBS-g2c

This library contains C decoder/encoder routines for GRIB edition 2.
Other
17 stars 11 forks source link

Changing occurrence of C++ reserved name 'template' in header file #450

Closed keltonhalbert closed 8 months ago

keltonhalbert commented 8 months ago

This is a rather small PR, but I figured it would be worth contributing back to the main repository since I may not be the only person who tries to do this.

C++ is cool in that you can call compiled C code natively just by adding a special header include statement, in addition to performing the linking step against the static or shared library:

extern "C" {
#include <grib2.h>
}
...

Such a use case is desireable because g2c can be used to interact with and read the grib2 data, and then higher-level abstractions in C++ (such as std::unordered_map) can be used to handle grouping of array data and metadata.

However, the current g2c header file has a few occurrences of variables named template, which is a C++ reserved name, and this conflict prevents compiling a C++ program that calls g2c. This only matters for the header file, and not for the compiled .c files. I renamed the two occurences of template as g2c_template, which successfully allows for C/C++ cross compilation.

Fixes #452