r/C_Programming • • 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

70 Upvotes

79 comments sorted by

View all comments

Show parent comment

1

u/DawnOnTheEdge Jul 29 '26 edited Jul 29 '26

If you want an exact-width array parameter, not a VLA,double(*xyz)[3] does work, although so does struct Point3d. It’s just really inconvenient to use.

If you really need this functionality in C, the pragmatic solution is to pass some kind of array-slice structthat stores the bound, although that needs runtime checking. It often has a count followed by a flexible array member.

But we might actually be able to hack the kind of compile-time access-checking I’d like by writing a macro that expands to an access attribute on GCC/Clang and to SAL annotations on MSVC.