Sujet : Re: question about linker
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.cDate : 27. Nov 2024, 13:57:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vi7509$agj$3@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
On 27/11/2024 09:38, Thiago Adams wrote:
On 27/11/2024 09:10, Bart wrote:
On 27/11/2024 11:57, Bart wrote:
On 27/11/2024 01:52, Thiago Adams wrote:
>
I also use ILs for my compilers, but I write my own backends. I've worked on two diifferent kinds. One looks like a HLL, and only exists for my language. So this original source:
>
I was wondering if is possible to write C programs without struct/union?
I did this experiment.
struct X {
int a, b;
};
void F1() {
struct X x;
x.a = 1;
x.b = 2;
printf("%d, %d", x.a, x.b);
}
The equivalent C89 program in a subset without structs count be
#define M(T, obj, OFF) *((T*)(((char*)&(obj)) + (OFF)))
void F2() {
char x[8];
M(int, x, 0 /*offset of a*/) = 1;
M(int, x, 4 /*offset of b*/) = 2;
printf("\n");
printf("%d, %d", M(int, x, 0), M(int, x, 4));
}
The char array represents the struct X memory, then we have to find the offset of the members and cast to their types.
Does your IL have structs?
The QBE IL has aggregates types. I think this removes the front end calculate the the offsets.
https://c9x.me/compile/doc/il.html#Aggregate-Types