Skip to content
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

translate-c should not emit 'pub' for static functions #2314

Open
daurnimator opened this issue Apr 20, 2019 · 3 comments
Open

translate-c should not emit 'pub' for static functions #2314

daurnimator opened this issue Apr 20, 2019 · 3 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@daurnimator
Copy link
Collaborator

static void foo() {}
void bar() {
    return foo();
}

Running translate-c at the moment you get:

pub fn foo() void {}
pub export fn bar() void {
    return foo();
}
  • a heap of C builtin defines.

I don't expect pub on foo.

@emekoi
Copy link
Contributor

emekoi commented Apr 20, 2019

isn't static also a c way (hacky) for marking functions as private to that compilation unit?

@daurnimator
Copy link
Collaborator Author

isn't static also a c way (hacky) for marking functions as private to that compilation unit?

It's not "also", but the way to mark a function as private to a compilation unit.

The static keyword:

  • For file-scope functions and variables: marks it as private to the compilation unit
  • For function-scoped variables: marks them as statically allocated: the variables storage is for the lifetime of the program. The more practical meaning is: the value will be remembered across function invocations.

@andrewrk andrewrk added this to the 0.5.0 milestone Apr 21, 2019
@andrewrk andrewrk added accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. labels Apr 30, 2019
@andrewrk
Copy link
Member

andrewrk commented Apr 30, 2019

Note that it does need to put pub on static functions when doing a @cImport, so that the functions are exposed. But that's right - the command line translate-c should not. There's an enum value given to the implementation to distinguish.

If you think about it, if the file is supposed to be used with #include then static functions should be pub. But if the file is supposed to be used with -o foo.o -c foo.c and linked in later, then the static functions should not be pub.

@andrewrk andrewrk added the translate-c C to Zig source translation feature (@cImport) label Jun 16, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 21, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Oct 23, 2019
@andrewrk andrewrk removed the accepted This proposal is planned. label Jan 2, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.10.0 May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

3 participants