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

stage2: support C-style main #12569

Open
nektro opened this issue Aug 22, 2022 · 2 comments
Open

stage2: support C-style main #12569

nektro opened this issue Aug 22, 2022 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@nektro
Copy link
Contributor

nektro commented Aug 22, 2022

Zig Version

0.10.0-dev.3665+9cf667a21

Steps to Reproduce

const string = [*:0]const u8;
const stringarray = [*:null]const ?string;

pub export fn main(argc: c_int, argv: stringarray) c_int {
    _ = argc;
    _ = argv;
    return 0;
}

Expected Behavior

successful compile and run

Actual Behavior

/home/meghan/src/zig/lib/std/start.zig:571:17: error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
                @compileError(bad_main_ret);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/meghan/src/zig/lib/std/start.zig:510:12: note: called from here
    return @call(.{ .modifier = .always_inline }, callMain, .{});
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/meghan/src/zig/lib/std/start.zig:460:36: note: called from here
    return initEventLoopAndCallMain();
           ~~~~~~~~~~~~~~~~~~~~~~~~^~
/home/meghan/src/zig/lib/std/start.zig:424:17: note: called from here
    std.os.exit(@call(.{ .modifier = .always_inline }, callMainWithArgs, .{ argc, argv, envp }));
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@nektro nektro added the bug Observed behavior contradicts documented or intended behavior label Aug 22, 2022
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Aug 22, 2022
@Vexu Vexu added this to the 0.10.0 milestone Aug 22, 2022
@Vexu
Copy link
Member

Vexu commented Aug 22, 2022

This doesn't seem to work with stage1 either:

$ zig run a.zig -fstage1
./lib/std/start.zig:571:17: error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
                @compileError(bad_main_ret);
                ^

@Vexu Vexu modified the milestones: 0.10.0, 0.11.0 Aug 22, 2022
@nektro
Copy link
Contributor Author

nektro commented Aug 22, 2022

yeah there seems to be odd conditions where it skips the check, but the minimal repro caught it so i thought it might be a regression

https://github.com/nektro/mount.ufs/blob/master/src/main.zig#L20 builds fine with stage1 even though i use the c_int main return here

@Vexu Vexu added standard library This issue involves writing Zig code for the standard library. and removed frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Aug 22, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

3 participants