Skip to content

Main procedures in Odin can't return a value ? #3097

Answered by z64
eleriaqueen asked this question in Q&A
Discussion options

You must be logged in to vote

Are you looking for os.exit()?

If you want to emulate something like int main() from C, for example, you can define another proc like run which does return a value. Then all your main does is call that function, and handle any error it returned accordingly - using os.exit() to abort with an exit code, or whatever you would like your specific application to do.

package main

import "core:os"
import "core:fmt"

main :: proc() {
    // your "real" `main`
    err := run()

    exit_code := 0
    exit_message: Maybe(string)

    // map error values to status codes & messages
    switch err {
    case .None:
        // OK
    case .Oops:
        exit_code = 1
        exit_message = "Oops..."

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@eleriaqueen
Comment options

@avelican
Comment options

Answer selected by eleriaqueen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants