I am new to C++ and am getting a compiler warning that I am not sure how to address. When I compile
INBAND1->RasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0);
with c++ calc_emissions.cpp -o calc_emissions.exe -lgdal
I get the warning
/usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.cpp: In function 'int main(int, char**)':
/usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.cpp:382:18: warning: ignoring return value of 'CPLErr GDALRasterBand::RasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, GSpacing, GSpacing, GDALRasterIOExtraArg*)', declared with attribute warn_unused_result [-Wunused-result]
INBAND1->RasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0);
~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My code runs fine with the warning, but I'd like to suppress or resolve the warning. My understanding is that the warning is due to RasterIO()
not having a return value (based on this). To suppress the warning, I tried INBAND1->(void)!RasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0);
as suggested here. However, that produces the following error
/usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.cpp: In function 'int main(int, char**)':
/usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.cpp:382:10: error: expected unqualified-id before '(' token
INBAND1->(void)!RasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0);
^
/usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.cpp:382:11: error: expected primary-expression before 'void'
INBAND1->(void)!RasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0);
^~~~
My impression is that adding (void)!
(or (void)
) doesn't work here because of the INBAND1->
part of the line. Any suggestions for how to handle this warning? Thanks.