Eliminate VLAs for the benefit of MSVC.

This commit is contained in:
Arthur O'Dwyer 2018-06-27 15:35:45 -07:00
parent 6753cc2e39
commit 62db7ee250
7 changed files with 21 additions and 22 deletions

View File

@ -8,7 +8,7 @@
CXXFLAGS += -std=c++11 -march=native -DMAC CXXFLAGS += -std=c++11 -march=native -DMAC
CXXFLAGS += -W -Wall -Wextra -pedantic CXXFLAGS += -W -Wall -Wextra -pedantic
CXXFLAGS += -Wno-format-pedantic -Wno-unused-parameter -Wno-missing-field-initializers -Wno-vla-extension CXXFLAGS += -Wno-format-pedantic -Wno-unused-parameter -Wno-missing-field-initializers
CXXFLAGS += -I/usr/local/include CXXFLAGS += -I/usr/local/include
CXXFLAGS += ${EXTRA_CXXFLAGS} CXXFLAGS += ${EXTRA_CXXFLAGS}

View File

@ -360,9 +360,9 @@ void sdltogl(SDL_Surface *txt, glfont_t& f, int ch) {
int theight = next_p2( otheight ); int theight = next_p2( otheight );
#if CAP_TABFONT #if CAP_TABFONT
int expanded_data[twidth * theight]; std::vector<int> expanded_data(twidth * theight);
#else #else
Uint16 expanded_data[twidth * theight]; std::vector<Uint16> expanded_data(twidth * theight);
#endif #endif
for(int j=0; j <theight;j++) for(int i=0; i < twidth; i++) { for(int j=0; j <theight;j++) for(int i=0; i < twidth; i++) {
@ -387,7 +387,7 @@ void sdltogl(SDL_Surface *txt, glfont_t& f, int ch) {
#else #else
GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
#endif #endif
expanded_data ); expanded_data.data() );
float x=(float)otwidth / (float)twidth; float x=(float)otwidth / (float)twidth;
float y=(float)otheight / (float)theight; float y=(float)otheight / (float)theight;

View File

@ -176,7 +176,7 @@ heptagon *createAlternateMap(cell *c, int rad, hstate firststate, int special) {
// okay, let's go then! // okay, let's go then!
cellwalker bf(c, gdir); cellwalker bf(c, gdir);
cell *cx[rad+1]; std::vector<cell *> cx(rad+1);
for(int i=0; i<rad; i++) { for(int i=0; i<rad; i++) {
cx[i] = bf.c; cx[i] = bf.c;
bf += revstep; bf += revstep;
@ -1347,4 +1347,4 @@ void moreBigStuff(cell *c) {
} }
} }
} }

View File

@ -2046,7 +2046,7 @@ void livecaves() {
vector<cell*> bringlife; vector<cell*> bringlife;
int gr = gamerange(); int gr = gamerange();
int heatvals[dcs]; std::vector<int> heatvals(dcs);
for(int i=0; i<dcs; i++) { for(int i=0; i<dcs; i++) {
cell *c = allcells[i]; cell *c = allcells[i];
@ -2991,7 +2991,7 @@ namespace ca {
if(cwt.c->land != laCA) return; if(cwt.c->land != laCA) return;
vector<cell*>& allcells = currentmap->allcells(); vector<cell*>& allcells = currentmap->allcells();
int dcs = isize(allcells); int dcs = isize(allcells);
bool willlive[dcs]; std::vector<bool> willlive(dcs);
for(int i=0; i<dcs; i++) { for(int i=0; i<dcs; i++) {
cell *c = allcells[i]; cell *c = allcells[i];
if(c->land != laCA) return; if(c->land != laCA) return;
@ -3126,9 +3126,9 @@ namespace windmap {
for(int i=0; i<N; i++) windcodes[i] = hrand(256); for(int i=0; i<N; i++) windcodes[i] = hrand(256);
bool inqueue[N]; vector<bool> inqueue(N, true);
vector<int> tocheck; vector<int> tocheck;
for(int i=0; i<N; i++) tocheck.push_back(i), inqueue[i] = true; for(int i=0; i<N; i++) tocheck.push_back(i);
hrandom_shuffle(&tocheck[0], isize(tocheck)); hrandom_shuffle(&tocheck[0], isize(tocheck));
for(int a=0; a<isize(tocheck); a++) { for(int a=0; a<isize(tocheck); a++) {

View File

@ -219,12 +219,11 @@ struct fpattern {
} else wsquare = 0; } else wsquare = 0;
#ifdef EASY #ifdef EASY
int sqrts[Prime]; std::vector<int> sqrts(Prime, 0);
for(int k=0; k<Prime; k++) sqrts[k] = 0;
for(int k=1-Prime; k<Prime; k++) sqrts[sqr(k)] = k; for(int k=1-Prime; k<Prime; k++) sqrts[sqr(k)] = k;
int fmax = Prime; int fmax = Prime;
#else #else
int sqrts[Field]; std::vector<int> sqrts(Field);
for(int k=0; k<Field; k++) sqrts[sqr(k)] = k; for(int k=0; k<Field; k++) sqrts[sqr(k)] = k;
int fmax = Field; int fmax = Field;
#endif #endif

View File

@ -201,9 +201,9 @@ void polylineColor(SDL_Surface *s, int *x, int *y, int polyi, int col) {
} }
void filledPolygonColorI(SDL_Surface *s, int* px, int *py, int polyi, int col) { void filledPolygonColorI(SDL_Surface *s, int* px, int *py, int polyi, int col) {
Sint16 spx[polyi], spy[polyi]; std::vector<Sint16> spx(px, px + polyi);
for(int i=0; i<polyi; i++) spx[i] = px[i], spy[i] = py[i]; std::vector<Sint16> spy(py, py + polyi);
filledPolygonColor(s, spx, spy, polyi, col); filledPolygonColor(s, spx.data(), spy.data(), polyi, col);
} }
#endif #endif

View File

@ -172,10 +172,10 @@ int compileShader(int type, const string& s) {
GLint logLength; GLint logLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) { if (logLength > 0) {
char log[logLength]; std::vector<char> log(logLength);
glGetShaderInfoLog(shader, logLength, &logLength, log); glGetShaderInfoLog(shader, logLength, &logLength, log.data());
if(logLength > 0) if(logLength > 0)
printf("compiler log (%d): '%s'\n", logLength, log); printf("compiler log (%d): '%s'\n", logLength, log.data());
} }
glGetShaderiv(shader, GL_COMPILE_STATUS, &status); glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
@ -232,10 +232,10 @@ struct GLprogram {
GLint logLength; GLint logLength;
glGetProgramiv(_program, GL_INFO_LOG_LENGTH, &logLength); glGetProgramiv(_program, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) { if (logLength > 0) {
char log[logLength]; std::vector<char> log(logLength);
glGetProgramInfoLog(_program, logLength, &logLength, log); glGetProgramInfoLog(_program, logLength, &logLength, log.data());
if(logLength > 0) if(logLength > 0)
printf("linking log (%d): %s\n", logLength, log); printf("linking log (%d): %s\n", logLength, log.data());
} }
glGetProgramiv(_program, GL_LINK_STATUS, &status); glGetProgramiv(_program, GL_LINK_STATUS, &status);