Deutsch   English   Français   Italiano  
<vi5m3v$3ljhl$2@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: BGB <cr88192@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: question about linker
Date: Tue, 26 Nov 2024 17:37:29 -0600
Organization: A noiseless patient Spider
Lines: 85
Message-ID: <vi5m3v$3ljhl$2@dont-email.me>
References: <vi54e9$3ie0o$1@dont-email.me> <vi56hi$3ie0o$2@dont-email.me>
 <vi57bh$3ip1o$2@dont-email.me> <vi58ba$3ie0o$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Nov 2024 00:37:35 +0100 (CET)
Injection-Info: dont-email.me; posting-host="d6b866aa0925367d3810d7714da21602";
	logging-data="3853877"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/FPr6DqrAjsHVRQZM6lGY3RWAjMLXS58A="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:qEc89UGIfCAdc9qYtH/X37ICZ0A=
Content-Language: en-US
In-Reply-To: <vi58ba$3ie0o$4@dont-email.me>
Bytes: 3655

On 11/26/2024 1:42 PM, Thiago Adams wrote:
> On 26/11/2024 16:25, Bart wrote:
>> On 26/11/2024 19:11, Thiago Adams wrote:
>>> On 26/11/2024 15:35, Thiago Adams wrote:
>>>>
>>>> (I think I know the answer but I would like to learn more.)
>>>>
>>>> I am using C89 as "compiler backend intermediate language".
>>>>
>>>> I want a very simple output that could facilitate the construction 
>>>> of a simple C89 compiler focused on code generation.
>>>
>>> Another question is.. does the compiler cares about function type 
>>> when calling a function or this is just an information to avoid 
>>> programmers mistakes?
>>
>> Yes.
>>
>> It will need to know about types anyway so that it can generate the 
>> correct code.
>>
>> While for function calls, different types may be passed in different 
>> registers.
>>
>> This is less critical for 32-bit code than for 64-bit, but presumably 
>> you will want your C89 code to be compiled to 64-bit code on 64-bit 
>> machines?
>>
>>>
>>> Consider this code:
>>>
>>> int main() {
>>>      strcmp("a", "b");
>>> }
>>>
>>> It compiles in -std=c89
>>>
>>> Now changing to -std=c99 -std=c11 it gives:
>>>
>>> error: implicit declaration of function 'strcmp'
>>>
>>>
>>> Then adding:
>>>
>>> int strcmp();
>>>
>>> int main() {
>>>      strcmp("a", "b");
>>> }
>>>
>>> it works in C99 / C11
>>>
>>> I think in C23 empty parameter list means no args, while in the 
>>> previous versions (void) means no args.
>>>
>>> Considering that in previous versions of C we could call a function 
>>> without its signature I think the compiler only needs the caller 
>>> side. (of course I am not considering programmer mistakes)
>>>
>>> So, I think one extra simplification for small compilers is to ignore 
>>> function parameters.
>>
>> I don't think so. But you are welcome to look at godbolt.org and see 
>> for yourself. Try this for example:
> 
> 
> 
> Yes..I realized now I am wrong. Considering function calls uses 
> registers I think the old C model works only when passing everything on 
> stack.
> 
> 

Can still sort of work:
If spill space is provided for any register arguments;
The mapping of arguments to registers does not depend on argument type;
Passing arguments auto-promotes to a consistent representation of the 
type (say, for example, 'float' auto-promotes to 'double', and 'int' 
auto-promotes to 'long', ...).

In this case, one can spill all of the register arguments into the spill 
space and then be back to an old linear memory argument list.

....