6 ms·
Zero sized types (and zero-length arrays, empty structures, etc) can be useful, and should not need to all have the same address (although in some cases they wi
by zzo38computer 1y ago
Zero sized types (and zero-length arrays, empty structures, etc) can be useful, and should not need to all have the same address (although in some cases they will have the same address, and in other cases it won't matter what the address is as long as it is nonzero), although you probably should not need to use dynamic allocation directly with such a type.
GNU C has a Elvis operator so that you can write "malloc(x?:1)" if you really need to do that.
If only a unique reference is needed (if it won't be used where other kind of pointers would also be used), and keeping track of allocation is wanted, one thing that may be possible is to just use a number, and then use a bit array to keep track of which numbers are in use.