Reputation: 339
It is just a random thought about the structures in a c program.
In C program __attribute__
provide a feature to specify special attributes when making a declaration.
section - Where a particular variable or a function can be placed at a particular address with the help of "section"
For example for a variable to be defined with attribute it can be done like this
int g1 __attribute__((section (".vector"))) = 100;
For a function to be defined with attribute it can be done like this
int some_function(void) __attribute__((section(".vector")));
int some_function(void)
{
int local_variabale1 = 100;
return local_variable1;
}
so from above examples it is possible to put the section .vector
at a particular address in which I specify the address in linked scripts.
Will there be a chance for structure in C to put the structure in section?
Suppose if this is my structure program
in c
struct database
{
int employee_number;
string name;
int phone_number;
};
If it is possible how can it be done?
Upvotes: 1
Views: 1507
Reputation:
Will there be a chance for structure in C to put the structure in section?
The definition of a structure doesn't exist anywhere in memory at runtime -- it's only used during compilation. As such, it doesn't make sense to give it a section.
If you're declaring an instance of that structure (e.g. struct database DB
), that's a variable, and that can be placed in a section. The structure itself isn't a variable, though.
Upvotes: 3