Deutsch   English   Français   Italiano  
<vmqkq3$vqg7$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!eternal-september.org!.POSTED!not-for-mail
From: Thiago Adams <thiago.adams@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: What is __STDC_HOSTED__ ?
Date: Wed, 22 Jan 2025 08:29:07 -0300
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <vmqkq3$vqg7$2@dont-email.me>
References: <vmpgui$hk8l$1@dont-email.me> <20250121181103.137@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 22 Jan 2025 12:29:07 +0100 (CET)
Injection-Info: dont-email.me; posting-host="50eb345c3ddfba260fbc8c3a848b3282";
	logging-data="1042951"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18rWblLXRO40TEXpFynugK8f3XxDrq0Wuw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:+WYUZknugFC+cRYAAUhcx54aXJI=
In-Reply-To: <20250121181103.137@kylheku.com>
Content-Language: en-GB
Bytes: 3286

Em 1/21/2025 11:36 PM, Kaz Kylheku escreveu:
> On 2025-01-22, Thiago Adams <thiago.adams@gmail.com> wrote:
>> standard says
>>
>> "__STDC_HOSTED__ The integer constant 1 if the implementation is a
>> hosted implementation or the
>> integer constant 0 if it is not."
>>
>> What is a hosted implementation?
> 
> A conforming hosted implementation is one which provides the full
> language, or almost the full language except for certain optional
> features, such as variable-length arrays in automatic storage.
> 
> The opposite of "hosted" is "freestanding". In a freestanding
> implementation, large portions of the library may be missing.
> The standard specifies exactly which header files and library
> features are required in a freestanding implementation,
> plus some other details.
> 
> For instance, the memory allocation functions like malloc,
> and I/O funtions in <stdio.h> are not required in a freestanding
> implementation.
> 
> "Hosted" referes to the concept that there is a host operating system
> platform, whereas "freestanding" refers to the concept of running on the
> bare metal, so to speak.
> 
> But those are only words; in ISO C they refer to feature sets. A
> freestanding implementation doesn't have to be embedded; such a thing
> can name sense on a platform that easily supports hosted implementations
> (e.g. server or desktop OS), for an application that provides its own
> bindings to the operating system: its own memory allocator, I/O streams.
> 
> In the GNU environment, we can use "gcc -ffreestanding" to get the
> behavior that the __STDC_HOSTED__ macro expands to 0.  However, I see
> that we can still use <stdio.h> in spite of that, and the library is
> linked.  "gcc -nostdlib" gets rid of the library linking.
> 
> So we have to use both together to get a facsimile of a freestanding
> implementation which announces itself as such. Perhaps:
> "gcc -nostdlib -ffreestanding -lgcc".
> 
> The -lgcc is neeeded because -nostdlib will remove libgcc also, and that
> may render the implementation nonconforming. libgcc provides
> run-time support for language features such as math operators, which are
> not optional in a freestanding implementation.
> 
thanks!