logoalt Hacker News

zabzonk12/08/20245 repliesview on HN

Purely out of interest, and probably my bad, but what is:

    (void)k_sz;
doing? I've seen fussy people doing:

     (void) printf( "hello" );
but not what you have written. As I say, probably ignorance on my part.

Replies

Sesse__12/08/2024

It's an idiom for telling the compiler “don't give a warning on this argument not being used, I know about it”. Not all compilers will heed it. Other choices include e.g. __attribute__((unused)) (GNU), [[maybe_unused]] (C++17/C23) or just not giving it a name (nonstandard, but very commonly supported).

show 2 replies
lang4d12/08/2024

That would be one way to silence an unused variable warning

ryanpetrich12/08/2024

This is to suppress a compiler warning that the k_sz argument is unused.

secondcoming12/08/2024

It silences 'unused variable' warnings.