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

Variable length array allocation in polyhedron.c is not supported on all platforms #1817

Open
g5t opened this issue Jan 22, 2025 · 2 comments

Comments

@g5t
Copy link
Contributor

g5t commented Jan 22, 2025

Allocating arrays with sizes determined by the value of a struct member, as in,

double dtime[a->nf];
Coords dpoint[a->nf];
double time[a->nf];
Coords point[a->nf];
int plane_number[a->nf];
int type[a->nf];

fails under Microsoft's C/C++ Optimizing Compiler Version 19.42.34435 for x64

E  cl.exe /DWIN32 /D_WINDOWS /Zi /O2 /Ob1 /DNDEBUG g\source.c /W0 /link /out:"g\source.exe"
E  failed with output
E  source.c
E  g\source.c(8491): error C2057: expected constant expression
E  g\source.c(8491): error C2466: cannot allocate an array of constant size 0
E  g\source.c(8491): error C2133: 'dtime': unknown size
E  g\source.c(8492): error C2057: expected constant expression
E  g\source.c(8492): error C2466: cannot allocate an array of constant size 0
E  g\source.c(8492): error C2133: 'dpoint': unknown size
E  g\source.c(8493): error C2057: expected constant expression
E  g\source.c(8493): error C2466: cannot allocate an array of constant size 0
E  g\source.c(8493): error C2133: 'time': unknown size
E  g\source.c(8494): error C2057: expected constant expression
E  g\source.c(8494): error C2466: cannot allocate an array of constant size 0
E  g\source.c(8494): error C2133: 'point': unknown size
E  g\source.c(8495): error C2057: expected constant expression
E  g\source.c(8495): error C2466: cannot allocate an array of constant size 0
E  g\source.c(8495): error C2133: 'plane_number': unknown size
E  g\source.c(8496): error C2057: expected constant expression
E  g\source.c(8496): error C2466: cannot allocate an array of constant size 0
E  g\source.c(8496): error C2133: 'type': unknown size

This method of variable length array allocation would appear to be part of the C99 standard, but according to Microsoft

The compiler doesn't implement several required features of C99, so it isn't possible to specify C99 conformance, either.

Trying either of the supported language specifications, /std:c11 or /std:c17 does not allow an instrument using the polyhedron intersection code to compile for this tested version of the Microsoft C compiler.

Replacing this construction with paired allocation and freeing memory should be more cross-platform friendly.

@g5t
Copy link
Contributor Author

g5t commented Jan 22, 2025

This same construction appears elsewhere. Notably in supermirror-lib.c

int n_skip_plane = 2; int skip_plane[n_skip_plane];

g5t added a commit that referenced this issue Jan 22, 2025
Replace variable length array allocation with initializer-list allocation.
@willend
Copy link
Contributor

willend commented Jan 22, 2025

@g5t thanks for giving a hand with this.

I corrected many such static allocation syntaxes for the "initial windows conda support", but have apparently overlooked these.

willend added a commit that referenced this issue Jan 22, 2025
Remove variable length array allocations for #1817
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

2 participants