-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Replace extern
with extern(...)
and layout(...)
#4245
Comments
I don't get these parts: struct layout(.C, .Packed) {}; How can a struct be both packed, and conform to the C abi? |
In #3977 it was proposed (and accepted) by @andrewrk himself so I think that's planned.
The
The |
Good catch @Sobeston! I remembered the rule incorrectly; for some reason I thought that
I think that's fair, and a counter to this proposal might be just to document it better. Either way, it took me some digging to find out what |
I've updated the proposal to address packing. It's shorter now! 👍 @LemonBoy My knowledge is limited, but I assumed weak linkage for externs is on the table coz of #1917. If that's not necessarily true, I could definitely shrink this proposal way down to just cover Otherwise, my line of thinking was that by pulling the thread a bit, it would make sense to consolidate |
It's on the table (and on the pending PR queue) but I'm still not sure if
It makes sense to export some |
What about the OpenGL bindings use case? comptime code would use |
Will be solved by #8643. |
The title isn't meant as proposed syntax but summarizes the proposal's intent.
Background
I see two issues that make the
extern
keyword somewhat unintuitive:Note: Use of
extern
for calling convention is superceded bycallconv
but has not yet been removed from the language. Perhaps it is already planned to do so.Proposal
extern
. To specify calling convention, usecallconv()
.extern
with a new keyword for specifying non-Zig layout of structs/enums/unions (i.e. C or packed).extern
(in the context of declaring an external) to specify linked library name, weak vs. strong, etc.With this,
extern
would be consigned to variable/function declarations, such that it only means one thing: "There exists an external...".😵 -> 😎
Details
Layout
Introduce a
layout
keyword which takes an enum value:This would be consistent with how
align
andcallconv
are suffixed qualifiers.Externals
Some examples to demonstrate various possibilities:
A similar "options struct" for
@extern()
was already discussed: #3971 (comment)I'm not too familiar with thread-local or the nuances of linkage; forgive me if any of the above is nonsensical.
One readability issue is that
const
andvar
get shoved to the right, burying information about mutability. This can already happen for externs, though to a lesser extent. To address this, we could consider reordering things so thatextern
qualification suffixes the identifier. (I am fond of this syntax, so if it sparks interest I would open a separate proposal.)Thoughts and questions
With the ability to supply options for
extern
, would we even need@extern()
? If not, could we follow a similar path and replace@export()
with a configurableexport
?Going farther outfield:
extern
is used for both declarations ("there exists an external") and definitions (give a default value to an external). Could we consignextern
to the former, and only useexport
for the latter?Related: #1522, #1917
The text was updated successfully, but these errors were encountered: