2,730 questions
4
votes
3
answers
127
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
197
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,...