Questions tagged [variable-length]

Refers to anything whose length can vary

Refers to anything whose length can vary

290 questions
11
votes
3 answers

Get max length of multi-dimension tuple

My tuple looks something like this(for a particular set of generated value) tTrains = [ (3, ), (1, 3), (6, 8), (4, 6, 8, 9), (2, 4) ] Now, what I need to find is the length of longest tuple inside this tuple/list. I can always use a for loop,…
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
10
votes
3 answers

How do you prevent variable-length arrays from crashing when there is not enough memory?

Before variable-length arrays were supported, I would dynamically allocate them like this: int foo(size_t n) { int *arr = malloc(n * sizeof int); if (!arr) return ENOMEM; /* not enough memory */ . . else do stuff with arr[] . …
Henry
  • 529
  • 5
  • 16
10
votes
4 answers

Variable length template arguments list?

I remember seing something like this being done: template class X : public ListOfTypenames {}; that is, X inherits from a variable length list of typenames passed as the template arguments. This code is hypothetical, of course. I…
sold
  • 2,041
  • 5
  • 25
  • 32
9
votes
5 answers

Iteratively find all combinations of size k of an array of characters (N choose K)

I am currently working on this problem as a personal project. Basically: Given an array of elements, e.g. E = {1,2,a,b} and Given a number, K, e.g. K = 2 I want to return all Combinations of E of size K (E choose K) E.g. {{1,1}, {1,2}, {1,a},…
8
votes
4 answers

How to replace values in va_list?

I want to do some exercise about va_list. This is my code. int myscanf( char* fmt, ... ) { va_list ap; va_start ( ap, fmt ); vfscanf ( stdin, fmt, ap ); va_end ( ap ); } int main() { int a, b; myscanf( "%d %d", &a, &b ); } As I shown…
hwliu
  • 205
  • 2
  • 6
8
votes
3 answers

What does (int (*)[])var1 stand for?

I found this example code and I tried to google what (int (*)[])var1 could stand for, but I got no usefull results. #include #include int i(int n,int m,int var1[n][m]) { return var1[0][0]; } int example() { int *var1…
Framester
  • 33,341
  • 51
  • 130
  • 192
7
votes
2 answers

Variable-Length Operators In Reverse Polish Notation (Postfix)

Background: In traditional Reverse Polish Notation, all operators must have fixed lengths, which allows RPN to be easily evaluated and manipulated by code because every token, expression, and subexpression are all "self-contained" such that one can…
Jack G
  • 4,553
  • 2
  • 41
  • 50
7
votes
4 answers

Number of Unique Obs by Variable in a Data Table

I have read in a large data file into R using the following command data <- as.data.set(spss.system.file(paste(path, file, sep = '/'))) The data set contains columns which should not belong, and contain only blanks. This issue has to do with R…
Andreas
  • 1,923
  • 19
  • 24
7
votes
5 answers

Finding length of all arrays multidimensional array, Java

I would like to use a multidimensional array to store a grid of data. However, I have not found a simple way to find the length of the 2nd part of the array. For example: boolean[][] array = new boolean[3][5]; System.out.println(array.length); will…
HedonicHedgehog
  • 592
  • 1
  • 6
  • 17
6
votes
6 answers

Why is void f(...) not allowed in C?

Why doesn't C allow a function with variable length argument list such as: void f(...) { // do something... }
Rajendra Uppal
  • 19,218
  • 15
  • 59
  • 57
6
votes
1 answer

Initializing a dynamically-sized Variable-Length Array (VLA) to 0

The following line of code, which creates a variable-length array on the stack: char name[length] = {'\0'}; Generates the following compiler diagnostics: error: variable-sized object may not be initialized warning: excess elements in array…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
6
votes
3 answers

Is it efficient to use length() in loops?

I have a lot of cases when I iterate over a vector in MATLAB, so I do this : len = length(vector) for i=1:len do_something(); end But this is just an intuition that says "prevent calling the length() function every time". Is it true? Or is it the…
jeff
  • 13,055
  • 29
  • 78
  • 136
6
votes
2 answers

Reading a Struct Within a Struct via PHP's Unpack Function

I want to know how to read a struct within a struct via php's unpack function. When I get an IS_MCI packet, I check it's Type to make sure it's equal to ISP_MCI, and then I check NumC to find out how many CompCar structs there are within this…
Mark Tomlin
  • 8,593
  • 11
  • 57
  • 72
6
votes
11 answers

When to use type.length-1; and type.length(); in java

I'm little bit confused when do I really need to use that length-1. I know that is when we don't want to have out of bound error. For instance I wrote this simple array: int [] oldArray = {1, 5, 6, 10, 25, 17}; for(int i = 0; i <…
user2888585
  • 63
  • 1
  • 1
  • 4
6
votes
0 answers

Need a good overview for Succinct Data Structures

Cross posted: Need a good overview for Succinct Data Structure algorithms Since I knew about Succinct Data Structures I'm in a desperate need of a good overview of most recent developments in that area. I have googled and read a lot of articles I…
datjko
  • 383
  • 1
  • 10
1
2
3
19 20