I am currently learning about the struct
data structure in C and how it is possible to preface this structure with the typedef
keyword. This causes the variable names of the actual structure to be placed in different namespaces as explained in several different references:
Difference between 'struct' and 'typedef struct' in C++?
typedef struct vs struct definitions
However, it is unclear as to what is occurring with the example that I am working with:
#include <stdio.h>
struct demo
{
short low_pass_vcf;
short filter_coupler;
short reverb;
short sequential;
} synth;
int main()
{
printf("Size of struct: %i\n", sizeof(struct demo));
printf("Size of struct: %i\n", sizeof(synth));
return 0;
}
In this example, I am able to access the struct
data structure through the synth
variable name; however, in the examples that I have seen, in order for me to be able to do this the struct
needs to be prefaced with typedef
. In this example, typedef
is not used and yet I am still able to reference this structure through synth
. I am wondering what exactly is occurring that C is allowing me to do this? Any explanation would be appreciated. Cheers.