Yes, you have it right. When a struct is declared, the type, size and location of each var in the struct is remembered. The order of those vars is also important. Physically, each var in the struct is located at a specific offset from the starting address of the struct. Also, each var is located immediately after the previous one within the struct.
It's also important to understand that the field names within the struct are not actually variable names. When a struct TYPE is created, no variables have been created yet. When a struct var is created, it contains fields with all those field names. These are not pointers to unique vars that exist somewhere else (unless, of course, the field really is defined as a pointer that points to something else.) The field names within a struct type don't identify a unique var created by a program, they only identify a field within the struct type. The names are reused for the fields in every var of that struct type, but the combination of the struct var name and the field name within that struct are what identify a unique value.
A struct is identified in a program by it's name, like bf
is in the code you posted. If you wanted to access a specific field or var within that struct, you would use the .
operator. Say that you wanted to access bfSize in the bf struct. You would use bf.bfSize
. bf
identifies the struct and bfSize
identifies the field within the struct. If you also had bf2
and wanted to access it's bfSize field, use the same logic, bf2.bfSize
. It's really that simple. Hopefully, this helps.
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)