Fix error C2020: 'parms': 'struct' member redefinition - #91
Conversation
|
I don't know why the Windows compiler might be complaining about this, but the suggested patch is an ugly way to deal with the problem. I'll produce something cleaner. |
|
I just checked out the spandsp repo on a Windows 11 PC with Visual Studio 2022. I compile and do not see the C2020 error. Is this error with a different version of Visual Studio? |
|
@coppice-git |
|
and yes Visual Studio 2022 is the main version to use. |
|
@coppice-git SpanDSP headers are broken to use on Windows without this PR. Therefore no way to use the latest SpanDSP master. |
|
@coppice-git ping |
|
@coppice-git See if you like this more |
|
View the scan-build logs here: https://github.com/freeswitch/spandsp/actions/runs/30476949144/artifacts/8734087507 |
|
I fixed this on 4/2/2025 with the 2 lines below. This is an obvious problem to any senior engineer with MS C compiler experience (your comments and change in the code are correct): |
|
View the scan-build logs here: https://github.com/freeswitch/spandsp/actions/runs/30493216737/artifacts/8740621356 |
<windows.h> (shared/minwindef.h) defines the legacy 16 bit memory model
keywords "near" and "far" as empty macros. In any translation unit that
includes it ahead of spandsp/expose.h, that strips the names from the near
and far members of struct v150_1_state_s:
struct { v150_1_near_far_t parms; ... } ; /* was } near; */
struct { v150_1_near_far_t parms; ... } ; /* was } far; */
MSVC then treats both as anonymous structs and flattens their members into
the enclosing struct, where the two "parms" members collide. The error names
"parms" rather than near/far because those tokens are gone before the
compiler sees them.
Undefine both macros around the struct in private/v150_1.h, restoring them
with #pragma pop_macro at the end of the header. private/v150_1.h is an
installed header, so it must not leave a consumer's macro state altered.
v150_1.c refers to the members by name and is the only file that does, so it
undefines the macros locally after its includes.
|
View the scan-build logs here: https://github.com/freeswitch/spandsp/actions/runs/30571174377/artifacts/8770913226 |
No description provided.