Skip to content

#pragma GCC breaks CLANG and older GCCs #79

@StefanBruens

Description

@StefanBruens

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions