variable-length-array Questions

2

Solved

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 f...

3

Solved

The intent of this question is to provide a reference about how to correctly allocate multi-dimensional arrays dynamically in C. This is a topic often misunderstood and poorly explained even in som...

2

Solved

I know that the restrict qualifier in C specifies that the memory region pointed by two pointers should not overlap. It was my understanding that the Linux (not SUS) prototype for memcpy looks like...

8

Solved

Why do I receive the error "Variable-sized object may not be initialized" with the following code? int boardAux[length][length] = {{0}};
Epinasty asked 21/6, 2010 at 7:52

1

Solved

Does typedef VLA require evaluation of the size expression? int f(void); int main(void) { typedef int (T) [ f() ]; // is f required to be evaluated ? T x; return sizeof x; } Does typedef pointe...
Proteose asked 25/2, 2022 at 16:45

2

Solved

int read_val(); long read_and_process(int n) { long vals[n]; for (int i = 0; i < n; i++) vals[i] = read_val(); return vals[n-1]; } The assembly language code compiled by x86-64 GCC 5.4 is: ...
Unmeriting asked 17/10, 2021 at 15:21

3

As my usually used C++ compilers allow variable-length arrays (e.g. arrays depending on runtime size), I wonder if there is something like std::array with variable size? Of course std::vector is of...
Poeticize asked 31/12, 2013 at 12:42

6

Solved

I understand what variable length arrays are and how they are implemented. This question is about why they exist. We know that VLAs are only allowed within function blocks (or prototypes) and that...
Hagridden asked 20/3, 2014 at 10:40

4

Solved

I'm trying to figure out how alloca() actually works on a memory level. From the linux man page: The alloca() function allocates size bytes of space in the stack frame of the caller. This temporar...
Pistole asked 1/10, 2021 at 13:46

10

Solved

I haven't used C very much in the last few years. When I read this question today I came across some C syntax which I wasn't familiar with. Apparently in C99 the following syntax is valid: void f...

5

Solved

I have a situation, where I have to apply a criteria on an input array and reuturn another array as output which will have smaller size based upon the filtering criteria. Now problem is I do not ...
Picador asked 26/12, 2010 at 18:50

5

Solved

How can I enable the use of VLAs, variable length arrays as defined in C99, in MS Visual C++ or that is not possible at all? Yes I know that the C++ standard is based on C89 and that VLAs are not a...
Heliogravure asked 9/3, 2011 at 14:5

8

Solved

The implicit conversion of a Python sequence of variable-length lists into a NumPy array cause the array to be of type object. v = [[1], [1, 2]] np.array(v) >>> array([[1], [1, 2]], dtype...
Nidify asked 27/7, 2016 at 17:1

2

Solved

I have the next two code examples: const char *val = strchr(ch, ' '); const int diff = (int)(val - ch); char arr[diff]; and const char *val = strchr(ch, ' '); const int diff = (int)(val - ch); c...
Sylvanus asked 10/3, 2021 at 14:8

4

Solved

I thought C had no more surprises for me, but this surprised me. const int NUM_FOO = 5; .... int foo[NUM_FOO]; ==>error C2057: expected constant expression My C++ experience has made me ...

4

Solved

In C++ I tried declaring a global array of some size. I got the error: array bound is not an integer constant before ‘]’ token But when I declared an array of the same type in the main() funct...
Camion asked 10/3, 2020 at 15:25

4

Solved

For most of my undergrad C programming course, we studied C99 and our lecturer never bothered to teach us the main differences between C99 and previous versions. We have recently been informed that...
Glomerule asked 19/1, 2020 at 16:8

3

Solved

#include <iostream> using namespace std; void aa(int n) { int test[n] = {0}; } int main() { aa(10); return 0; } and got error: variable-sized object may not be initialized but #incl...
Cecilycecity asked 25/11, 2019 at 6:55

3

Solved

In any normal compiler for C or C++, variable length arrays are working normally but in Visual Studio Community 2019, VLAs are not working. How can i in any way use Visual Studio as an IDE (becasue...
Id asked 19/10, 2019 at 10:48

1

Solved

Is this undefined behavior? The relevant parts of the standard don't say much. size_t n = SIZE_MAX / sizeof(double) + 1; size_t m = sizeof(double[n]);
Intoxicated asked 3/9, 2019 at 3:23

4

Solved

How is it possible to declare a variable-length array as a global variable ? when variable length array is declared in a function before the length is scanned, it compiles but does not run. it gi...
Calv asked 28/4, 2012 at 3:46

2

Solved

Compelled to use the variable length array feature for my auxiliary function that prints square matrices, I defined it as follows: void print_matrix(M, dim) unsigned dim; int M[dim][dim]; { /* ...
Cathode asked 27/3, 2019 at 23:55

2

Solved

I was reading about dynamic memory allocation and static memory allocation and found the following about dynamic memory allocation: In the programs seen in previous chapters, all memory ne...
Diffusivity asked 13/12, 2018 at 10:50

1

Solved

As you may know, VLA's haves pros and cons and they are optional in C11. I suppose that the main reason to make VLA's optional is: "the stack can blow up": int arr[n]; /* where n = 1024 * 1024 * ...
Vespid asked 18/11, 2018 at 9:0

3

Solved

#include <iostream> using namespace std; int main() { int rows = 10; int cols = 9; int opt[rows][cols] = {0}; for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { ...
Rosanarosane asked 31/8, 2018 at 16:31

© 2022 - 2024 — McMap. All rights reserved.