Re: What is __STDC_HOSTED__ ?

Liste des GroupesRevenir à cl c 
Sujet : Re: What is __STDC_HOSTED__ ?
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.c
Date : 22. Jan 2025, 12:29:07
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vmqkq3$vqg7$2@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
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!

Date Sujet#  Auteur
22 Jan 25 * What is __STDC_HOSTED__ ?5Thiago Adams
22 Jan 25 +* Re: What is __STDC_HOSTED__ ?2Kaz Kylheku
22 Jan 25 i`- Re: What is __STDC_HOSTED__ ?1Thiago Adams
22 Jan 25 `* Re: What is __STDC_HOSTED__ ?2James Kuyper
22 Jan 25  `- Re: What is __STDC_HOSTED__ ?1Thiago Adams

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal