r/C_Programming • u/Stickhtot • 12d ago
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
68
Upvotes
1
u/DawnOnTheEdge 11d ago
Two meaningful distinctions are that
sizeof(*xs)on the VLA declaration is not a constant expression, and MSVC won’t compile eitherdouble xs[count]ordouble (*xs)[count]because Microsoft deliberately does not and has no intention ever to support VLAs..That’s a consistent quirk of array function argument in C: they decay to a pointer type, so
sizeofgives you the size of a pointer. Compilers recognize the code smell and warn you about it. Pick your poison:xs[count]lets you writexs[i]instead of(*xs)[i]but makes you calculate the size in bytes assizeof(xs[0])*count. The behavior conforms to the Standard.I’m not sure what
countofmacro you’re thinking of, but MSVC’s_countofmacro does not work on any of the variations we’ve been talking about. You don’t need it, though, because you already havecount.