tmolteno / necpp

NEC2++ is a C++ rewrite of the Numerical Electromagnetics Code (NEC-2) with many new features like automatic error detection when you specify the structure incorrectly and much faster execution. Nec2++ can analyse radiating as well as scattering properties of structures. The simulation engine in Nec2++ is compiled into a library for easy integration into automatic antenna design systems or GUI tools. Examples are included for using Nec2++ from C/C++, Ruby and Python.
http://elec.otago.ac.nz/w/index.php/Necpp
GNU General Public License v2.0
241 stars 65 forks source link

#pragma GCC breaks CLANG and older GCCs #79

Open StefanBruens opened 1 year ago

StefanBruens commented 1 year ago

This pragma is incompatible with older GCCs and CLANG:

https://github.com/tmolteno/necpp/blob/870f110875ef7e1fc951cbd489fde20ac9a93284/src/nec2cpp.cpp#L590-L593

[   56s] nec2cpp.cpp: In function 'int readmn(FILE*, FILE*, char*, int*, int*, int*, int*, nec_float*, nec_float*, nec_float*, nec_float*, nec_float*, nec_float*)':
[   56s] nec2cpp.cpp:591:32: error: unknown option after '#pragma GCC diagnostic' kind [-Werror=pragmas]
[   56s]  #pragma GCC diagnostic ignored "-Wstringop-truncation"

The correct approach is to use strncpy(gm, "EN", 3); or memcpy(gm, "EN", 2); and remove the #pragma.

And the function signature can be changed to
int readmn(FILE*, FILE*, char[3], int*, int*, int*, int*, nec_float*, nec_float*, nec_float*, nec_float*, nec_float*, nec_float*).

This allows the compiler to check the array bounds at compile time.