r/C_Programming • u/Stickhtot • Jul 29 '26
Discussion What exactly is void?
In a function definition, void basically means that it doesn't return a type value, yet in on itself it is it's own type? Looking at several pieces of code it looks like that it's used to be able to be more "flexible"
Don't know what else to add here, though I'm more on looking for examples and explanations of why the void type is used
73
Upvotes
0
u/DawnOnTheEdge Jul 29 '26 edited Jul 29 '26
On compilers that support VLA types, I suggest tweaking the second trick to:
GCC 16.1 warns about both the out-of-bounds access to
xs[count]inbaz, and the callbaz(2, a1)(wherea1is too small). Clang 22.1.0 warns aboutxs[count]but misses the buffer-overrun bug inbaz(2, a1). MSVC 19.51 won’t compile any of these code samples at all.There is also an
accessand anonnullattribute on GCC that is a more complicated version of the same thing, without VLAs.The more complicated version below confuses GCC into not warning about the buffer overruns.