简体   繁体   English

ANSI C - > Arrays - >在文件范围内可变地修改

[英]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. 虽然我正在尝试用ANSI中的C语言探索数组的可能性,但我遇到了一个问题。 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. 我已经看到'const'类型可能会产生这种问题。 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]; 宏执行直接文本替换,因此在预处理器阶段之后它与char *ptrlig[5000];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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