-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
ability to include arbitrary C source text in @cImport blocks #2070
Comments
+1. This might be a particularly good solution to #1085 because it could be used to solve a bunch of other problems that nobody can think of yet. For example, if there's something that you can do in C but not in Zig, you could define a C function to do the thing and then call that from Zig (I think). |
Note that you can already do something very similar with status quo: const c = @cImport({
@cInclude("curses.h");
@cInclude("mycode.h");
}); mycode.h: static const int MY_A_STANDOUT = A_STANDOUT; |
To exe.addIncludeDir("."); Now |
I think this feature would be really useful.
We wouldn't need them as builtins, but could have them as functions in the std library instead. |
There are a hand full of languages that have taken this approach such as mercury, ats2 and would remove the need of creating separate C source files though I'd be concerned about debugger and editor support for the code contained. I guess a reason for would be the ability to replace C code function by function inline if you could embed all of it but that is also rather messy closer to the 40-60% replaced mark and would promote more C use in zig code as I see it. |
Solved instead by #20630 |
Inspired by #1085 (comment)
Here's a use case:
This would be incredibly easy to implement. It's just a question of whether it's a good idea.
And then there's the follow-up question of, do we really need
@cInclude
,@cDefine
, and@cUndef
if we have the all-powerful@cSource
?The text was updated successfully, but these errors were encountered: