2,730 questions
1
vote
1
answer
63
views
The reason of there being constraints on the second argument of `va_start()`
I've found that there are conditions that the second argument of va_start(ap, last) must satisfy, which are:
last must not be a register variable
last must not be a function
last must not be an array
...
-4
votes
1
answer
82
views
C++ preprocessor VARARGS - invalid syntax in a NodejS header file
I'm experimenting a bit with trying to build NodeJS 24.11.1 with GCC 13.4.0 on an older OS X system, mostly as a can-it-be-done project.
Regardless of the reasons, among the hurdles that could be ...
Best practices
0
votes
15
replies
196
views
In C with stdarg, how can I pass a va_list to another function safely?
man stdarg shows, under the va_args macro description:
If ap is passed to a function that uses va_arg(ap,type), then the value of ap is undefined after the return of that function.
If we look at ...
1
vote
1
answer
36
views
Make ipywidget.interact take ndarray arguments
I couldn't find exactly my scenario in other questions, please redirect me if you see fit but:
I have a function with args with variable length, which i check inside and take different actions based ...
15
votes
3
answers
2k
views
Why does a mismatching printf specifier also affect subsequent arguments?
I have a very simple C program where I am printing variables of different sizes.
#include <stdio.h>
unsigned int long long a;
unsigned int c;
int main() {
a = 0x1111111122222222;
c = ...
3
votes
3
answers
467
views
How to define variadic **argv in C function
Here is the variadic example:
https://en.cppreference.com/w/c/variadic.html
I want to define two functions but I don't know how to do it correctly.
The "foo" function should accept "...
10
votes
2
answers
123
views
Why is the AL field (FP register usage count) necessary in the SysV ABI?
I was going through the System V AMD64 ABI and couldn’t find a clear explanation for why the AL field (which tracks how many floating-point registers are used) is necessary.
From my understanding, ...
0
votes
1
answer
248
views
Is it safe to use `(void) va_arg(...)` to advance the `va_list` in C? [closed]
I have a C function that uses va_list but needs to skip the first two arguments in here:
static size_t event_type_CURSOR_POS__weight( const void * self, va_list * app )
{
(void) va_arg( *app, ...
1
vote
4
answers
214
views
Is it possible to somehow contain an extern "C" function within a header file?
Due to templates being templates, they need to be defined in a header file (making explicit instantiations is not an option). I have an extern function which takes an expanded template parameter pack:
...
2
votes
1
answer
170
views
variable number of arguments with -fstack-protector-strong
I am just wondering why the following code by using va_start, the addresses of the stack parameters are not in order anymore. va_start is a gcc builtin. But how can it change the addresses of the ...
1
vote
2
answers
142
views
Trying to split parameter pack into two smaller packs using an index sequence and nested lambdas leads to weird compiler behaviors
So I was trying to come up with a way to split a given parameter pack args... into two separate packs args1... and args2... (at some specified index, 3 in this case). I also wanted to minimize the ...
3
votes
3
answers
262
views
More placeholders than arguments for 'printf'
I know that we can do more arguments than placeholders when using printf, in which case, the excessive arguments are simply ignored:
printf("%s", "Hello friend!\n", "Long time ...
3
votes
0
answers
99
views
How to override a varargs java method in a scala class which is still callable in both scala and java variadically?
Assume there is a base class in a Java library which cannot be modified
public class BaseClass {
public Something function(int... args){ ... }
}
Typically, this would be overridden in Scala by ...
4
votes
1
answer
161
views
Is it legal to empty-initialize `va_list` with `{}` in C23 before calling `va_start()`?
TL;DR: is C23's universal initialization type var = {}; safe for all types, including standard opaque ones, such as va_list?
I have code that uses variable arguments. An older version of a static ...
1
vote
1
answer
65
views
Lua stack and vararg functions
I'm curently exploring Lua (5.4.7) vm implementation, it's relatively simple but i can't figure our how return works in case of vararg functions.
functions with fixed amount of params are quite simple,...
3
votes
2
answers
138
views
calling function with variable argument list using const arguments
Does any of the C Standards describe any kind of a check to ensure that const is used and accessed appropriately with variable argument lists?
If I have the following source for a function with a ...
3
votes
2
answers
121
views
Why does scanf() read only after specified text?
I was doing a CTF reversing challenge when I came across this C code in Ghidra:
int main(void)
{
int iVar1;
char input[32];
fwrite("Password: ",1,10,stdout);
__isoc99_scanf("...
1
vote
1
answer
80
views
How to call varargs method in ByteBuddy in a way that bakes the arguments array as constants into the bytecode?
I'm generating classes with ByteBuddy. In one place, I need to call a static utility method which accepts varargs of type String. My code looks like this:
String[] myStringArray = generateParameters()
...
2
votes
2
answers
218
views
Is there a way to use both named args and variable args in a function call?
Going through a code review and found named argument call being used to a argument that uses the spread operator for variable args (vargs). To my suprise it works fine for 1 argument, but I cannot ...
3
votes
2
answers
97
views
Can alloca() cause stack corruption in a variadic function when arguments are mismatched?
I'm using alloca() inside a variadic function to allocate stack memory dynamically based on an integer argument. However, I'm concerned about what happens if the argument is mismatched (e.g., passing ...
0
votes
1
answer
72
views
GCC converting <varargs.h> to <stdarg.h>
I'm trying to convert some very old C on AIX7.3 to use stdarg instead of varargs. The code was originally compiled with XLC, but I'm being forced to use gcc now. I'm trying to avoid the need to ...
0
votes
1
answer
64
views
What is the best way to take in optional parameters in this case? [closed]
I have a function in my library to modify the state of a given light. When the inputted mode is flashing, I want to allow the caller to pass in the interval time, on time, off time, and some other ...
-1
votes
1
answer
110
views
functional conversion with variable number of args to something plain in C++
I need to do something like this:
I have a big black box solver solver(f, ...) that takes a function (for example) as input:
double f(x, a, b, c) {
return 0.0
}
The a, b, c varies and the solver ...
3
votes
1
answer
155
views
How to call vsprintf multiple times on the same argument list?
I would like a function I can call this way:
my_printf(int unimportant,
"%-10s", "a string",
"%5.1f", 1.23,
format_string, ...
2
votes
2
answers
104
views
How can I define a vararg with three types in Java?
Since I need a Java method to receive any number of objects of three specific classes I decided to use a vararg ... to implement it. However, I have the restriction that these three classes are:
java....
1
vote
1
answer
55
views
Segmentation fault encountered at `ret void` in llvm-ir instructions
I'm currently making a compiler that outputs bare LLVM-IR instructions and implementing variadic function calls. I have defined a println function that accepts a (format) string and variable amount of ...
1
vote
1
answer
125
views
Why does this C function use of stdarg breaks when compiled by clang for Apple Silicon?
The following function MsCommand_push does not work as expected when compiled with Apple clang version 15.0.0 (clang-1500.3.9.4). It is supposed to take as input a variable number of pointer to char (...
1
vote
1
answer
113
views
Kotlin varargs to array
There is a function I want to call in a third-party library:
fun foo(strings: Array<String>)
The array strings is only used for reading, i.e. foo doesn't write to it.
Now, I want to write a ...
1
vote
2
answers
39
views
Is there way to add one more argument to the function(which has var args) with default value without breaking existing calls?
I have a function
fun foo(
id: String,
vararg values: Int,
){
...
}
and there are calls like these
fun bar1(){
foo("id_1")
foo("id_2", 1)
foo("id_3&...
1
vote
2
answers
205
views
How to skip default named arguments while setting a named variadic argument in a function call?
I have an existing method:
public function dbQuery(
string $query,
bool $flag1 = false,
int $flag2 = SOME_DEFAULT,
bool $flag3 = false
)
Now I want to adapt it so it is possible to ...
1
vote
2
answers
232
views
Why does my variadic macro throw an error when nothing is passed?
Context
I'm trying to create a C program that takes multiple integers as input via the print(...) macro, without needing to pass the length of arguments manually from the main function. To achieve ...
2
votes
2
answers
221
views
How to create nested variadic functions?
I can't and won't bore you with the details, but my system has these specific requirements:
Actions must be called and registered at runtime.
Each Action can have multiple targets, and these targets ...
-1
votes
1
answer
107
views
How to deal with multiple types on var_arg in c++? [closed]
How to do that?
The code is causing: null pointer dereference.
10-08 17:26:00.835 5249 5617 D DigestGenerator: /apex/com.android.runtime/lib/bionic/libc.so!libc.so (strstr+) ()
10-08 17:26:00.835 ...
0
votes
2
answers
103
views
Passing a variadic function to a variadic function via a pointer
I'm kinda confused with the usage of <stdarg.h> features. I can't figure out how to properly pass a va_list to the argument function. Here's a simplified example of what I'm trying to achive:
#...
0
votes
1
answer
77
views
Intercepting and redirecting fcntl calls
fcntl is defined as a vararg function int fcntl(int fd, int action, ...) which sometimes takes an int arg and sometimes void* arg.
I'd like to write a logging interceptor for this libc function (using ...
0
votes
0
answers
51
views
How can I annotate variadic generics in Python? [duplicate]
I have a generic class:
class A[T]:
pass
And a function that extracts T from A:
def func[T](arg: A[T]) -> T:
pass
Now my function can accept *args and extract all Ts from all of the given As. ...
0
votes
2
answers
433
views
Why are java varargs arrays [closed]
Recently I had a situation where it was logical to use varargs in java. I then found out that varargs are just syntactic sugar for arrays, and was curious about the performance repercussions that ...
1
vote
2
answers
148
views
Method overloads with vararg
When designing a (performant) method with variable parameter length like
<T> void consume(T t1)
<T> void consume(T t1, T t2)
<T> void consume(T t1, T t2, T t3)
and a) another ...
1
vote
1
answer
125
views
How to transform or unpack *args types for typing variadics
I want to annotate a function that combines several iterators or generators into one, the case for two iterators is trivial:
def merge_two_iterators[T, H](
gen1: Iterator[T],
gen2: Iterator[H]
...
1
vote
1
answer
204
views
Passing a variadic variable to another function accepting variadic parameter in Swift [duplicate]
I'm currently working on a Swift project and encountered an issue when trying to pass a variadic parameter from one function to another.
Specifically, I expected that I could directly pass the ...
0
votes
3
answers
89
views
Can I pass object array as multiple arguments of params method in C#?
For example I have C# method like this:
void someMethod(String arg1, params object[] extras)
{
foreach (object extra in extras)
{
Console.WriteLine(extra);
}
}
When I call it like ...
0
votes
1
answer
111
views
typescript - cannot pass a function parameters with the same type of its parameters
Here is a basic version that demonstrates the issue. Does anyone know why I cannot pass the return value to the wrapped function? The javascript works but typescript is not allowing it.
// accept a ...
1
vote
1
answer
80
views
format string and vararg - can I tell compiler to check them?
I have the following function for Logging purposes:
void LogE(const char* scope, const char* s, ...) {
fprintf(stderr, "%s : ", scope);
va_list list;
va_start(list, s);
...
0
votes
1
answer
80
views
Type for heterogeneous *args
In typed Python, how do you type a *args list that you're expecting to pass to another argument that is a higher kinded function?
For example, this function takes a function and its first argument and ...
1
vote
3
answers
198
views
expand parameter pack with boolean operation
I tried to do function that checks if the argument matches specific values.
I think know how to do it with recursion or std::initializer_list, but I want to do it with fold. Here is non working code:
...
0
votes
1
answer
601
views
Using `std::apply` to iterate over `std::tuple` [duplicate]
I am trying to call a particular member function in all elements of a tuple using std::apply. This works when I use a lambda but not when defining a free function.
Following Template tuple - calling a ...
4
votes
1
answer
237
views
va_arg - different behavior on Linux and Windows
I did some test code to demonstrate different output on Windows and Linux
#include <stdarg.h>
#include <stdio.h>
void print_vint(va_list args)
{
int i = va_arg(args, int);
printf(&...
-2
votes
1
answer
190
views
sizeof(va_list) = 24 not 8
By definition, in stdarg.h typedef char* va_list.so the size of va_list should be 8 not 24 in ubuntu 20.04 64bits gcc 9.4.0, i don't know why i get the size of va_list is 24?
I runed the following ...
0
votes
2
answers
103
views
Convert `(String, Int)...` variadic parameter function to Dictionary for ExpressibleByDictionaryLiteral
I have objects that are currently initialized via one-parameter init functions that take an Array or Dictionary.
I've realized that I can use ExpressibleByArrayLiteral and ...
1
vote
0
answers
43
views
Unable to propagate variable args from one variadic function to another [duplicate]
I have read the following about passing arguments to variadic functions,
https://stackoverflow.com/a/3530807/22299201
#include<stdio.h>
#include<string.h>
#include<stdarg.h>
#define ...