2

I have seen this expression in the code of other developer and I cannot get the meaning of it, the code line is:

typedef struct _Space Space;

So, for the syntax I reckon that _Space is a kind of variable or something similar but I do not know what kind of variable it is (integer, string, Boolean, etc).

Anyone have any idea??

  • Aside - defining struct with name starting with underscore is technically an *undefined behavior* according to the C standard. I see this practice very common, but it looks like people are simply feeling uncomfortable to have the same name for the struct and it's typedefed alias, which is in fact perfectly fine. Unlike the leading underscore. – Eugene Sh. Jan 31 '19 at 20:33
  • @EugeneSh. This is practically ubiquitous in the Windows SDK struct definitions – Govind Parmar Jan 31 '19 at 20:34
  • 2
    @GovindParmar I would consider windows API as the "implementation" for which these identifiers are reserved. And not to forget that MS does not comply with C standards... – Eugene Sh. Jan 31 '19 at 20:35

1 Answers1

4

struct _Space refers to a definition of a struct _Space elsewhere. The typedef ... Space means you can refer to a struct _Space as simply Space, saving you some typing.

For example, consider the difference in brevity and clarity between

struct _Space mySpace; // Oh god! memories

vs

Space mySpace;
Govind Parmar
  • 20,656
  • 7
  • 53
  • 85