Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#pragma GCC breaks CLANG and older GCCs #79

Open
StefanBruens opened this issue Feb 19, 2023 · 0 comments
Open

#pragma GCC breaks CLANG and older GCCs #79

StefanBruens opened this issue Feb 19, 2023 · 0 comments

Comments

@StefanBruens
Copy link

This pragma is incompatible with older GCCs and CLANG:

necpp/src/nec2cpp.cpp

Lines 590 to 593 in 870f110

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy( gm, "EN", 2 );
#pragma GCC diagnostic pop

[   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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant