Necessity of function prefix with (void)

I recently met a rather unusual coding convention in which a function call that returns "void" is prefixed with (void).

eg.

(void) MyFunction();  

What is the difference from a function call:

MyFunction();  

Did he get any advantage or another unnecessary, but some kind of conditional agreement?

+5
source share
6 answers

, printf(), , ( printf, ). , lint, , , , - :

int n = printf( "hello" );

void:

(void) printf( "hello" );

- , , . , , .

+12

, - , void, .

, , , ( ), , .

+2

-, void (!) (, gcc , ) ( ); , , "" ( ).

0

acedemically: "" -, . : " , , , "

0

- , - ?

. , . , , return, , .

0

man- HPUX , , , lint.

fprintf(mystream, "%s\n", "foo");

.

(void)fprintf(mystream, "%s\n", "foo");

This may be the place where the author of the code comes from. IMO, this is not a great idea, because most sprintf families, for example, are called malloc. malloc will fail if there is not enough memory. SIGINT also causes the main call to write () syscall to interrupt and not write the entire buffer, for members of the printf () family.

0
source

All Articles