简体   繁体   中英

ANSI C -> Arrays -> Variably modified at file scope

While I'm trying to explore possibilities of arrays in C in ANSI, I'm confronted with an issue. Here's my code:

#include <stdio.h>
#include <string.h>

static int MAXLIGNE = 5000;
char *ptrlig[MAXLIGNE]; // PTR SUR LA LIGNE DE TXT // GOT AN ISSUE : 
                        // VARIABLY MODIFIED PTRLIG @ FILESCOPE

int lirelignes(char *ptrlig[], int nlignes);
void ecrirelignes(char *ptrlig[], int nlignes);
void trirapide(char *ptrlig[], int gauche, int droite);

Error from the GCC :

VARIABLY MODIFIED PTRLIG at FILESCOPE

I've seen that 'const' type may create that kind of issues. I tried to make it like :

#include <stdio.h>
#include <string.h>

static int MAXLIGNE = 5000;
unsigned char *ptrlig[MAXLIGNE];

But that doesn't seem to change anything in this case.

The length of an array defined at file scope must be a compile time constant, and the value of another variable does not qualify as such.

If you want to use a name for the length of this array, you'll need to use a macro:

#define MAXLIGNE 5000
char *ptrlig[MAXLIGNE]; 

The macro does a direct text substitution, so after the preprocessor stage it is the same as char *ptrlig[5000];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM