Skip to main content

Questions tagged [variable-length-array]

A variable length array (VLA) is an array in C99 and other languages whose size is non-constant.

variable-length-array
0 votes
0 answers
16 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. ...
Venusaur's user avatar
  • 191
-2 votes
2 answers
88 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 ...
Muhammad Muttaqin's user avatar
-3 votes
0 answers
70 views

i can't specify the size of my array using a variable in VS, but if I do it with other IDEs it works [duplicate]

This is the code in VS: int main(){ int hi = 5; int arr[hi]{}; } The error: Error(active) E0028 expression must have a constant value The same code in code::Blocks: int main() { int ...
the ghost's user avatar
4 votes
1 answer
111 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) ...
Harith's user avatar
  • 7,235
2 votes
3 answers
120 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 "...
GrandeKnight's user avatar
6 votes
2 answers
115 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 ...
Lover of Structure's user avatar
2 votes
3 answers
242 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 ...
B-rad's user avatar
  • 55
-1 votes
2 answers
117 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("%...
Shuvarthi Dey's user avatar
1 vote
1 answer
211 views

How do I construct an instance of a DST struct whose size is only known at runtime?

I have a struct that can be used in a fixed-size or unsized way, where the last element is an array of u8 items. We can write the following struct definition: struct MyStructImpl<E: ?Sized> { ...
Bernard's user avatar
  • 5,377
-1 votes
1 answer
61 views

clarifications on assembler code when declaring an array with a size decided at runtime

I'm trying to understand how sizeof() works, so I made 2 arrays, and see what is assembled, I've not used -O3 option because I thought the code to be clearer and the code is not deleted by ...
sefiroths's user avatar
  • 1,563
2 votes
3 answers
421 views

Return slice (or array of unknown size) from match expression

I'm trying to implement the following idea: let command = ...; let request = match subcommand { Some(x) => [command, x as u8, (x >> 8) as u8], None => [command], }; request ...
Roman Liutko's user avatar
0 votes
1 answer
233 views

Multiplot of variable length data using gnuplot

Here I have two data files with model parameters and RMSEs computed for them. I would like to get those RMSEs plotted for each model separately with the model also displayed on it. Please help. Data ...
user86927's user avatar
0 votes
0 answers
36 views

Using a variable in format string of Fortran and display the values side-by-side [duplicate]

I understood through this post on how to use a variable in format string. write(*,'(1x,f10.5)')(j(i),i=1,nvar) seems to work but the values in 'j' are displayed row-wise. I want them to be displayed ...
user86927's user avatar
30 votes
2 answers
2k views

Linux memcpy restrict keyword syntax

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 - ...
tinkerbeast's user avatar
  • 2,069
1 vote
3 answers
113 views

Array using functions on C

A program to accept an array and diplay it on the console using functions. Program should contain 3 functions including main() function. Next two functions for accepting values to the array, and ...
Amalshanth's user avatar

15 30 50 per page
1
2 3 4 5
29