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

about using structs to pass arguments #7

Open
izabera opened this issue Mar 23, 2016 · 0 comments
Open

about using structs to pass arguments #7

izabera opened this issue Mar 23, 2016 · 0 comments

Comments

@izabera
Copy link

izabera commented Mar 23, 2016

your example with run_server( "3490" ); doesn't work if the struct has default arguments

#include <stdio.h>
struct run_server_options {
    char * port;
    int backlog;
};

#define run_server( ... ) \
    run_server_( ( struct run_server_options ){ \
        /* default values */ \
        .port = "45680", \
        .backlog = 5, \
        __VA_ARGS__ \
    } )

int run_server_( struct run_server_options opts )
{
    printf("port: %s backlog: %d\n", opts.port, opts.backlog);
}

int main( void )
{
    return run_server( "3490" );
}

this code adds too many elements to the struct
"3490" is totally ignored and the output is port: 45680 backlog: 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant