438 questions
1
vote
1
answer
90
views
UB when passing a multi-dimension array of one form to function parameter expecting another
I'm looking at the C2Y draft n3467 and trying to wrap my heads around something involving functions taking VLAs.
It seems there's an undefined behavior that's not mentioned by the standard. That is:
...
0
votes
2
answers
64
views
C++ - Candidate function not viable: no known conversion from 'double[10][Globals::MAX_COL]' to 'double (*)[Globals::MAX_COL]'
When compiling my program, I get the following error:
No matching function for call to 'fillWithRandomNum'
Candidate function not viable: no known conversion from 'double[10][Globals::MAX_COL]' to '...
1
vote
0
answers
71
views
Why does the compiler allocate too much memory?
I have a bit of C code for an ARM Cortex-M0 chip, for which I was investigating the disassembly:
int func2(unsigned a) {
int h[a];
for (unsigned i = 0; i < a; i++) {
h[i] = 0;
}
int ch;...
20
votes
6
answers
2k
views
Where is the size of a VLA stored in C?
In C, you can do this:
int arr[i];
From what I understand, this is called a VLA—variable length array—which is an array whose size is not known at compile time, which in most implementations is ...
3
votes
2
answers
90
views
Specifying dimension of array in function and outside function does not give same result
This compiles fine under C99
const int DIM;
int main() {
int tab[DIM];
}
while the following gives the error
int tab[DIM];
int main() {
}
error: variably modified tab at file scope
Why?
I know ...
2
votes
1
answer
97
views
Is definition of variable length array (VLA) / known constant size recursive?
Issue: definition of variable length array (VLA) / known constant size seems to be recursive.
C11, 6.2.5 Types, 23 (emphases added):
A type has known constant size if the type is not incomplete and ...
5
votes
1
answer
127
views
What is the order of evaluation of VLA dimensions?
Is the following code:
#include <stdio.h>
void case1(int array[][printf("hello ")][printf("world ")]) {}
int i = 0;
void case2(int array[][i++][i++]) {}
int main(void) {
...
1
vote
1
answer
91
views
Support for `sizeof T[n]` in the Frama-C framework
I am wondering how difficult it would be to add rudimentary support for something like sizeof T[n] (which to my knowledge is an explicit C construct for a variable length array), to be used in a ...
0
votes
0
answers
24
views
Why VLA is comparable to gets?
It is well-known that MSVC doesn't, and won't support VLA feature.
During searching MSVC online reference, I found somewhat interesting sentence:
Variable length array (VLA) support isn't planned. ...
-2
votes
2
answers
110
views
How do I store integers into 2 different arrays in C programming
The first array is multiples of 5, second array is multiple of 9. I was able to store the input but the printed array seems wrong as it did not print my supposed numbers. Any kind soul could help and ...
4
votes
1
answer
127
views
Check if array is a VLA at compile-time
@Lundin shows how to check if a passed expression is an array at compile-time here: Lvalue conversion of _Generic controlling expression involving array clang warning wrong?:
#define IS_ARRAY(T) ...
2
votes
3
answers
145
views
How to assign anonymous VLA to pointer?
Currently I am assigning a VLA to a pointer as follows
struct Foo {
int* array;
};
int array[size];
struct Foo foo = {
.array = array;
};
Is it possible to replace this with an "...
6
votes
2
answers
126
views
What are the exact conditions under which type_name in sizeof(type_name) is evaluated? GCC evaluates f() in sizeof(int [(f(), 100)])
Context
The standard says (C17, 6.5.3.4 ¶2):
The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined from ...
2
votes
3
answers
399
views
Why is stack memory usage in C++ determined at compile time?
I first started going down this rabbithole after learning that VLAs (variable length arrays) are not compatible with C++. This is due to the fact that an array of variable length would not have a size ...
0
votes
2
answers
120
views
What is the explanation of the odd behaviour in the size of the array in the given code? [duplicate]
#include<stdio.h>
int main(){
int n;
printf("Enter the number:");
scanf("%d",&n);
int array[n];
for (int i=0;i<=n;i++){
printf("%...