ok, I just want to note, I understand the basic methods of a struct, but I'd like to understand deeper...

how exactly does a struct work on the CPU??
(where and how does it store the code template, how is it called, and what is it stored as)

I'm trying to figure out the logic for my visual language, UGESL, previousely named UMCSL:
images: (old ideas, concepts, and tests)

thanks :)

It's not really that advanced, but conceptually, structures are stored and accessed as a punned array with padding between the "objects" to facilitate faster individual access by the CPU (which some compilers can optionally change or remove to alter or make consistent the storage size).

The template, which I interpret to mean the order and type of members, is handled by the compiler's symbol table. It's unlikely to be retained in compiled object code.

Structure accesses, such as mystruct.member is your compiler magic and under the hood it's turned into something like *(type*)((char*)mystruct + offset) where offset is the byte index of the member in the structure memory block from the symbol table.

As far as the CPU is concerned, structures aren't special at all. The only real difference from a scalar variable and a structure member is the initial offset calculation to find the member in a heterogeneous "array".

Once again, all of this is conceptual in nature. Compilers are free to implement structures however they want, provided all of the rules are met and public interfaces exhibit correct behavior. But what I described above is the most immediately obvious and straightforward potential implementation.

I get what you're saying, it's all compiler magic...

I suppose I could work around this and make it identify structures and such.
(writing UMCSL using ASM and have UMC identify the structs and classes from the base-code)

This article has been dead for over six months. Start a new discussion instead.