Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

about using structs to pass arguments #7

@izabera

Description

@izabera

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions