It appears some compilers behave non-standard when given an const integer as array declarator expression.
I don't remember ever hitting this, but apparently the pure environment of godbolt does show it.
It appears some compilers behave non-standard when given an const integer as array declarator expression.
I don't remember ever hitting this, but apparently the pure environment of godbolt does show it.
What exactly do you refer to as "non-standard" here?

It appears some compilers behave non-standard when given an const integer as array declarator expression.
I don't remember ever hitting this, but apparently the pure environment of godbolt does show it.
What exactly do you refer to as "non-standard" here?Technically const int size = 50; isn't an "Integer constant expression" valid for use in the array declarator.
But some compilers allow it, because why shouldn't it be possible, it's not changing anyway, so it can derive the value.
After all, there is a valid integer constant expression literal being used, but just one reference away.
Then when you run the compiler with strict rules by specifying the standard it should follow, it says that it can't allow it. Which is technically correct, the best kind of correct.
But some compilers allow it, because why shouldn't it be possible, it's not changing anyway, so it can derive the value.
Um... Some C compilers allow it because they support VLA. An array with const int size is perfectly standard in C, as long as it is recognized as a VLA by the compiler and behaves as a VLA afterwards. Nothing non-standard about it.
An implementation may accept other forms of constant expressions.

On the gripping hand, I would rather surmise that the compilers allowing such construct are not relaxing VLA constraints, but rather taking advantage of paragraph 10 of ch 6.6 Constant Expressions:Quote from: mon livre de chevetAn implementation may accept other forms of constant expressions.
Well, I disagree about a static storage duration array declared with a const int as dimension (or some equivalent expression) being a VLA in any way.

!mentioned that it would compile with GCC

mentioned that it would compile with GCC
I tried the original code with Gcc v4.1.2 on a PowerPC-7410 machine, got compiled and worked correctly![]()
![]()
A patch may have been applied to Gcc, I cannot verify it.
as an extension


People not liking macros just need to get over it when writing C. Insisting on avoiding them will usually lead to writing non-standard C

#define array_SIZE 1024
uint8_t array[ array_SIZE ];
however, it's the only exception to what I suggested to avoid in the other topic and I still strongly suggest: to avoid all other (ab)uses of the pre-processor.So I suppose your declarations were at file scope? (Because it's still not 100% clear from what you said.)
const unsigned int data_size = 32;
unsigned char data[data_size];
const unsigned int sense_len = 256;
unsigned char sense[sense_len];
as global definition, outside a function.
In the original C file, there is only one single .c file with no .h files.
One file, one program, and at some point, you readCode: [Select]const unsigned int data_size = 32;as global definition, outside a function.
unsigned char data[data_size];
const unsigned int sense_len = 256;
unsigned char sense[sense_len];
It immediately compiled as is with gcc v4.1.2. When I removed "const" still the code got compiled, and in both cases it worked correctly.
So I suppose your declarations were at file scope? (Because it's still not 100% clear from what you said.)
In the original C file, there is only one single .c file with no .h files.
One file, one program, and at some point, you readCode: [Select]const unsigned int data_size = 32;as global definition, outside a function.
unsigned char data[data_size];
const unsigned int sense_len = 256;
unsigned char sense[sense_len];
It immediately compiled as is with gcc v4.1.2. When I removed "const" still the code got compiled, and in both cases it worked correctly.
Great! But when I moved the code to AvogetCC, it didn't get compiled at all. The compiler doesn't understand VLAs (there are 21 points to be rewritten), and doesn't like 'const',
# 2022-05-28: GCC v9 and older no longer receive upstream support or fixes for bugs.
# Please switch to a newer GCC version using gcc-config.
# The lowest supported version of GCC is GCC 10.
<sys-devel/gcc-10
(plus, they removed all the building eclass support ... and, off course, the new ones are incompatible with the old one)gcc test.c -o test
gcc-v4.1.2, PPC7450, 32bit/BE
test.c:2: error: variably modified 'data' at file scope
test.c:4: error: variably modified 'sense' at file scope
gcc-v9.4.0, PPC7450, 32bit/BE
test.c:2:15: error: variably modified 'data' at file scope
2 | unsigned char data[data_size];
| ^~~~
test.c:4:15: error: variably modified 'sense' at file scope
4 | unsigned char sense[sense_len];
| ^~~~~
/* test.c */
const unsigned int data_size = 32;
unsigned char data[data_size];
const unsigned int sense_len = 256;
unsigned char sense[sense_len];
int main()
{
return 0;
}

Note that with later versions of the C std, VLAs became optional IIRC.
[...]
__STDC_NO_VLA__ The integer constant 1, intended to indicate that the implementation does not support variable length arrays or variably modified types.
void foo()
{
const unsigned int data_size = 32;
unsigned char data[data_size];
const unsigned int sense_len = 256;
unsigned char sense[sense_len];
}
int main()
{
foo();
return 0;
}
Note that this is going (probably) to change again in C23, where VM types will be mandatory, as well as VLA with allocated storage duration
Code: [Select]void foo()
{
const unsigned int data_size = 32;
unsigned char data[data_size];
const unsigned int sense_len = 256;
unsigned char sense[sense_len];
}
int main()
{
foo();
return 0;
}
for completeness, I repeated the test: this compiles on Gcc v4.1.2, doesn't compile on AvogetCC
Note that this is going (probably) to change again in C23, where VM types will be mandatory, as well as VLA with allocated storage duration
There are two modules in modern Firefox that require VLA; I didn't look at the code, but I am 100% sure because I remember a patch that didn't nothing but enable them with a define. Hope they don't mess too much, it's already a mess supporting Firefox, especially on ancient machines where you cannot always have the latest compier feature on hand.