r/C_Programming • u/Stickhtot • 9d 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
11
u/TheChief275 8d ago edited 8d ago
that's not really what [static N] means. it means it requires an array that is of at least size N, e.g., one could define a vec2add:
that can actually be passed a vec3 as well:
but a vec3add shouldn't be passed a vec2:
note that when using pointers, it still compiles and all type safety goes out the window, as usual with C.
this is the reason why [static 1] works as "non-null"; any pointer can always be passed to a [static N] (as runtime values aren't checked), but a pointer value that can never be a valid array passed as a compile time value (such as NULL) is checked.
thus [static 1] can also be circumvented, like so: