#I don't understand the syntax of structs

37 messages · Page 1 of 1 (latest)

granite oar
#

Intuitively they don't make sense

Such as

typedef struct{
  int thing;
}name;

struct name{
  int thing;
}

struct{
  int thing;
}name;

latent sleetBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

granite oar
#

some1 explain why this is

#

why does

typedef struct name{
  int thing
}
``` not work
#

and what the differences between the 3 are

little kiln
granite oar
#

its so sucky tho D:

#

It does not make alot of sense

stuck dragon
#

this is the actual struct syntax

#

and you have to do struct name variable_name; to create a variable with the struct type

#

but because people are lazy, they dont like typing struct everywhere

#

so you can use typedef to create an alternate name for the struct

#

like typedef the_type name;

#

so you can do typedef struct name name; and then you only need name variable_name; to use the struct

#

and then```c
typedef struct {
int thing;
} name;

#

is making name to mean the unnamed struct that you just declared

#

does that make sense?

granite oar
#

sorta

#

why do we have to say the name twice

#

I dont get that part for

stuck dragon
# granite oar this

struct name is the struct type, and then the second name is the new name for the type

granite oar
#

oh wait what

#

so what if I did stuct cheese pizza

#

I doubt anyone would ever do that

#

but for learning purposes

#

how would I reference this?

stuck dragon
granite oar
#

then what is the purpose of cheese

#

its the type but like

#

wut

stuck dragon
#

then struct cheese is how you refer to the cheese struct

granite oar
#

I see

#

Thank you!

#

!solved