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

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

Path: ...!news-out.netnews.com!s1-1.netnews.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!nntp-feed.chiark.greenend.org.uk!ewrotcd!nntp.terraraq.uk!news.gegeweb.eu!gegeweb.org!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: Tue, 26 Nov 2024 16:38:23 -0300
Organization: A noiseless patient Spider
Lines: 101
Message-ID: <vi583f$3ie0o$3@dont-email.me>
References: <vi54e9$3ie0o$1@dont-email.me> <vi56tj$3ip1o$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 26 Nov 2024 20:38:23 +0100 (CET)
Injection-Info: dont-email.me; posting-host="582870763c644d3bdda32f5308bc8ee6"; logging-data="3749912"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19EcwUBZVzLbeGvY6XW1qdKVKtKZs2PzhQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:YE64dWhc01AIdEHUNSqovMzmEio=
In-Reply-To: <vi56tj$3ip1o$1@dont-email.me>
Content-Language: en-US
Bytes: 4229

On 26/11/2024 16:18, Bart wrote:
> On 26/11/2024 18: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.
>>
>> I am removing these features from the generated code.
>>
>>   - typedef
>>   - enum
>>   - preprocessor
>>   - const
> 
> I don't use them in generated code either. (Only in a brief section at 
> the top to define my prefered type designations.)


I am generating the prototypes for all functions called.
No includes, no macros.

The generated code is depending on compiler flags , platform and 
headers. It is intended to direct usage like in the pipeline

use my_compiler -> C89 -> CC


> 
>>
>> At this output, I am generating the prototypes for the functions I call.
>>
>> For instance,
>> int strcmp( const char* lhs, const char* rhs );
>>
>> is generated as
>>
>> int strcmp( char* lhs, char* rhs );
> 
> I don't use #include either, not even for standard headers, although gcc 
> doesn't like it when I define my own std library functions. There are 
> ways to shut it up though.
> 
> 
>> I am also generating the structs as required (on demand). For the 
>> structs I am renaming it because I am generating all structs at global 
>> scope.
>>
>> Question:
>> Does the compiler/linkers? Cares If I am lying about const? Or If 
>> rename the structs?
>>
>> I think it does not care, and it seems to work (it compiles and run).
> 
> I don't know why the linker would care about anything. All it sees are 
> symbol imports and exports.
> 
> A compiler might care about lack of 'const' in that it could stop it 
> doing doing some optimisations.
> 
> But it can't report a type mismatch between 'const' and non-'const' 
> types if 'const' has been banished completely.
> 
> 

I think GCC has some builtin functions and he can complain if the 
function prototype differs.

Do you have any idea what else can be simplified when creating a C compiler?

I was thinking about literal strings.

Instead of

f("abc");

Generating something like

char literal_string_1[] = {'a', 'b', 'c', '\0' }; //or numbers global

f(literal_string_1);

The reason I believe compilers already have to do this right? (put 
strings in a data section)

So this was one extra simplification I was thinking about.
Also remove  loops (for , while) and switches.

I was considering to remove sizeof but I think this will be part 
(together with structs and align) of any compiler even simpler ones.

When thinking about this, I consider the first version of C, K&R was 
already very complete in terms of code generation.

The evolution of C is much more about facilities like enuns, compound 
literals than something that is created to code generation.