C/C++: Is there a specific reason why "void" was not simply defined as "typedef struct{} void" (i.e. an empty struct) with appropriate casting rules? [closed]

StackOverflow https://stackoverflow.com/questions/16631615

  •  29-05-2022
  •  | 
  •  

As an aside: Such a standard typedef would have help reduce the number of reserved words in C/C++, and relegated void to a simple type declaration, e.g. in <stddef.h>. (c.f. SRB in AB33/Mar 1972 - PDF=7kB)

有帮助吗?

解决方案

That's pretty speculative. But one good reason is because void is not an empty value; it's the absence of a value. For instance, a function with a signature of int f(void) takes zero arguments, not one.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top