Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Use (void) for empty function parameters

Open Yay295 opened this issue 1 year ago • 9 comments

I just happened to notice that these are the only three C functions that don't take any arguments and use () instead of (void) in their definition.

Yay295 avatar Apr 22 '24 17:04 Yay295

Ah, it looks like the webp functions are like that to get rid of the warning. They should actually have two parameters to match the PyMethodDef declaration, but if those parameters were added there would be a warning due to them being unused.

Yay295 avatar Apr 22 '24 18:04 Yay295

but if those parameters were added there would be a warning due to them being unused.

Can't you just use unnamed parameters to get rid of the warning?

nulano avatar Apr 22 '24 20:04 nulano

It looks like the solution in other places is just to cast it to the right type.

Yay295 avatar Apr 23 '24 15:04 Yay295

What is the benefit of (void) over ()? It's just a stylistic choice right, to try and more clearly communicate that there are no arguments?

If this is the general agreement, then sure, go ahead - but to me, requiring casting is a step too far for just a style preference.

radarhere avatar Apr 27 '24 10:04 radarhere

Casting is already used for this reason quite a lot elsewhere already. By "other places" I meant "other places in Pillow"; I wasn't talking about other projects.

https://github.com/python-pillow/Pillow/blob/c250a44177ac1e82d300aef702d5c2feef15fd03/src/_webp.c#L530-L536

https://github.com/search?q=repo%3Apython-pillow%2FPillow+%28PyCFunction%29&type=code

Yay295 avatar Apr 27 '24 14:04 Yay295

Casting is already used for this reason

None of those castings involve functions that have (void) for their parameters.

radarhere avatar Apr 27 '24 22:04 radarhere

The WEBP functions were removed in #8213, so it's just the one JPEG function now.

Yay295 avatar Aug 14 '24 13:08 Yay295

What is the benefit of (void) over ()? It's just a stylistic choice right, to try and more clearly communicate that there are no arguments?

radarhere avatar Aug 28 '24 22:08 radarhere

They technically have different meanings in C. func(void) means "this function does not take any arguments", while func() means "this function takes an undefined number of arguments of undefined types". I believe I saw this come up as a warning somewhere when compiling, but I don't remember where, or what flags I might have enabled.

Yay295 avatar Aug 28 '24 23:08 Yay295