-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functions with varargs support #196
Comments
I agree on that point. Any ideas how such a function could work? The problem is that sometimes it's hard to distinguish a vararg function from the call-site point of view: it may look (and even be declared?) as a normal function. Could we reuse the existing facilities of vararg functions in the CLI? Do these facilities even exist? |
dotnet/runtime#10478 that's not possible today, even if it would be possible in the future. So plan would be to mimic this. I think we can pass variadic arguments as |
To be honest, I'm not sure we can put a pointer into an Maybe some workaround using stack arrays or linked lists will be required. |
I do find some interesting sample which definitely will complicate our life. #include <stdio.h>
#include <stdarg.h>
void function1(char* s, ...)
{
va_list ap;
int tmp;
va_start(ap, s);
tmp = va_arg(ap, int);
printf(s, tmp);
va_end(ap);
}
void function2(char* s, int d)
{
printf(s, d);
}
typedef void (*functionX_t)(char*, int);
typedef void (*functionY_t)(char*, ...);
int main(int argc, char* argv[])
{
int x = 42;
/* swap! */
functionX_t functionX = (functionX_t) function1;
functionY_t functionY = (functionY_t) function2;
function1("%d\n", x);
function2("%d\n", x);
functionX("%d\n", x);
functionY("%d\n", x);
return 0;
} |
What does the standard say about this? I'm not sure these signatures are technically compatible. |
For now only char* arguments supported. Cannot do much with integers, since during emit phase I have lost information about expression type, and I cannot imagin what kind of IR node I need to preserve that, and at the same time do not overcomplicate things. Related to ForNeVeR#196
For now only char* arguments supported. Cannot do much with integers, since during emit phase I have lost information about expression type, and I cannot imagin what kind of IR node I need to preserve that, and at the same time do not overcomplicate things. Related to ForNeVeR#196
We can use __arglist and ArgIterator, which are built into DotNet (or copy the implementation, hehehehehe). They work well on Windows, but not so well on Unix. It would also solve the problem with 4 or 8 bytes in VA_ARG. |
Well, I'd say we want something that will reliably work on all the supported platforms and runtimes. |
We can switch to native va_list. I messed around with linux and windows and made a universal va_list that works on both operating systems. Also msvc generates its own wrapper over printf, where it packs the arguments into a va_list and calls vprintf. |
I do not like the solution involving any such hacks. Remember that we have to support at least 9 OS/CPU combinations (x86/x64/ARM64 macOS/Win/Lin). I do not believe there's a reliable solution for all those at once. And why would we want it anyway? Currently we aren't targeting that class of interop. |
We need varargs support, since almost any simple tutorial use
printf
. Without that support we cannot go to public probably, otherwise Cesium always look as toy project.Look for the number
196
in the code to find clues to implement this feature.The text was updated successfully, but these errors were encountered: