Deutsch   English   Français   Italiano  
<20250121181103.137@kylheku.com>

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: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.c
Subject: Re: What is __STDC_HOSTED__ ?
Date: Wed, 22 Jan 2025 02:36:49 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <20250121181103.137@kylheku.com>
References: <vmpgui$hk8l$1@dont-email.me>
Injection-Date: Wed, 22 Jan 2025 03:36:49 +0100 (CET)
Injection-Info: dont-email.me; posting-host="2c35b0c98faba819f3bd92f777297998";
	logging-data="608096"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18ZnfqzuqCX1TJT+dBvkUvIrmaUv9xo60A="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:n0XUWibDb/X6/uuAVgnV6xVVOxY=
Bytes: 3100

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.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca