Deutsch   English   Français   Italiano  
<vi7509$agj$3@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Thiago Adams <thiago.adams@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: question about linker
Date: Wed, 27 Nov 2024 09:57:45 -0300
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <vi7509$agj$3@dont-email.me>
References: <vi54e9$3ie0o$1@dont-email.me> <vi56tj$3ip1o$1@dont-email.me>
 <vi583f$3ie0o$3@dont-email.me> <vi59df$3ip1o$3@dont-email.me>
 <vi5qu0$3md4n$1@dont-email.me> <vi5u16$3me78$1@dont-email.me>
 <vi71f9$7be$1@dont-email.me> <vi727c$7be$2@dont-email.me>
 <vi73sh$agj$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Nov 2024 13:57:46 +0100 (CET)
Injection-Info: dont-email.me; posting-host="55a7253bc8aad96d55ac3768212cd6ac";
	logging-data="10771"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18u876r6mA9/N9PjGRPG+2IqS4B0CN6MXk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:jJ4REDoRDO8LKWPUOKSX2EaSKP4=
Content-Language: en-US
In-Reply-To: <vi73sh$agj$2@dont-email.me>
Bytes: 2455

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