1 year ago

#378527

test-img

user3758232

Single underscore as unused variable name in function signature?

I am building an interface in C which defines some function types with predefined signatures. Some implementations of this interface may not use some of the passed variables.

Is it a good / reasonable practice to use a Python-style single underscore in implementations that don't use certain arguments? The purpose is readability, but I don't know if that would confuse other devs reading the code even more.

E.g.:

// Interface definition

typedef int (*do_something_fn_t)(int a, float b);

typedef struct {
    char *name;
    do_something_fn_t do_something_fn;
} MyInterface;


// Implementation

int complex_calculation (int a, float _)
{ return a + 1; }

const MyInterface super_useful_int = {
    .name = "Super useful interface",
    .do_something_fn = complex_calculation,
};

c

naming-conventions

0 Answers

Your Answer

Accepted video resources