Newbie implementation query?

B

Beni

Ok, I did a google, an altavista, a yahoo and god knows what else, but
no link was satisfactory. So can please someone tell what a "hosted"
and a "freestanding" C implementation is, and whats the difference
between these two? And what defines which is what?
 
R

Richard Bos

Ok, I did a google, an altavista, a yahoo and god knows what else, but
no link was satisfactory. So can please someone tell what a "hosted"
and a "freestanding" C implementation is, and whats the difference
between these two? And what defines which is what?

<http://anubis.dkuug.dk/JTC1/SC22/WG14/www/docs/n869/>. Section four,
item 6. Also section 5.1.2, and 5.2.4.1 for a single different size
limit.

Put shortly and incompletely, a hosted implementation is one that runs
under the auspices of an OS, making use of its facilities for input,
output, and program running, while a freestanding implementation has no
such luxuries and need comply with fewer requirements than a hosted one.
Typical freestanding implementations can be found in the firmware of,
say, a microwave, a vending machine, or an elevator controller.

Richard
 
M

Martin Dickopp

Ok, I did a google, an altavista, a yahoo and god knows what else, but
no link was satisfactory. So can please someone tell what a "hosted"
and a "freestanding" C implementation is, and whats the difference
between these two? And what defines which is what?

Roughly speaking, a hosted environment depends on facilities provided by
an operating system, so a C program running under an OS is usually in a
hosted environment. A freestanding environment doesn't have the
facilities of an OS. Typical examples are the OS itself or C programs
running on embedded devices without OS.

As far as the C standard is concerned, a program in a hosted environment
can use all language features (inclunding the C library), and must have
a `main' function which adheres to some special conventions (e.g. it
must return `int'). A program in a freestanding environment cannot use
most of the library (only those facilities provided by <float.h>,
<iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and
<stdint.h>), and it is implementation-defined how such a program is
started.

Martin
 
C

Case

Martin said:
Roughly speaking, a hosted environment depends on facilities provided by
an operating system, so a C program running under an OS is usually in a
hosted environment. A freestanding environment doesn't have the
facilities of an OS. Typical examples are the OS itself or C programs
running on embedded devices without OS.

As far as the C standard is concerned, a program in a hosted environment
can use all language features (inclunding the C library), and must have
a `main' function which adheres to some special conventions (e.g. it
must return `int'). A program in a freestanding environment cannot use
most of the library (only those facilities provided by <float.h>,
<iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and
<stdint.h>), and it is implementation-defined how such a program is
started.

There are also environments that have full OS & C-library facilities and
in which the program 'runs under this OS', but still do not need/require
the 'special-meaning-main' function. Typical examples are some embedded
OSs (like VxWorks) in which any function can be the entry point of your
program.

Kees
 
D

Dan Pop

In said:
must return `int'). A program in a freestanding environment cannot use
most of the library (only those facilities provided by <float.h>,
<iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and
<stdint.h>),

Note that none of these headers is associated with *any* library support.
They are only supposed to define macros and provide typedef's.

So, it is more accurate to say that a program in a freestanding
environment cannot use *anything* from the standard C library.

It is also misleading, since, in practice, freestanding implementations
provide as much standard library support as reasonably possible.

Dan
 
M

Martin Dickopp

Note that none of these headers is associated with *any* library support.
They are only supposed to define macros and provide typedef's.

So, it is more accurate to say that a program in a freestanding
environment cannot use *anything* from the standard C library.

Yes, I have used the term "library facilites" in the same sense as verse
3 of the Introduction to the standard, i.e. I have counted any macro or
type definition provided by a library header as a "library facility".
It is also misleading, since, in practice, freestanding
implementations provide as much standard library support as reasonably
possible.

As I understood the OP's question, he asked about the definitions of
"hosted" and "freestanding", which in the context of this group means
the C standard definitions to me.

Martin
 
D

Dan Pop

In said:
Yes, I have used the term "library facilites" in the same sense as verse
3 of the Introduction to the standard, i.e. I have counted any macro or
type definition provided by a library header as a "library facility".

Not every header is a library header. In particular, all the ones
mentioned have exactly zilch to do with the library and everything to do
with the translator itself.
As I understood the OP's question, he asked about the definitions of
"hosted" and "freestanding", which in the context of this group means
the C standard definitions to me.

And the C standard definition *is* misleading, hence the need for the
additional comment. This newsgroup is NOT comp.std.c. There, I never
miss an opportunity to point out that the C standard makes portable
programming *practically* impossible on freestanding platforms (you have
to reinvent all the wheels from the standard library and you don't know
how to start and how to terminate your program).

Dan
 
M

Martin Dickopp

Not every header is a library header. In particular, all the ones
mentioned have exactly zilch to do with the library and everything to do
with the translator itself.

All the ones mentioned are library facilities in the sense of
Introduction#3.

Martin
 
J

Jack Klein

Ok, I did a google, an altavista, a yahoo and god knows what else, but
no link was satisfactory. So can please someone tell what a "hosted"
and a "freestanding" C implementation is, and whats the difference
between these two? And what defines which is what?

Despite what several others have posted, and inferences one might draw
from the "hosted" name used, the differences between hosted and
freestanding environments has nothing at all to do with an operating
system.

A hosted implementation must be able to successfully translate and
execute every strictly conforming program, which means among other
things that it must provide at least the minimum required
functionality for every single standard library function. Note many
such functions, such as malloc() or fopen(), are allowed to always
fail, if they return the proper indication for failure.

Normally hosted implementations are associated with desk-top and
larger systems that do have operating systems, but there is nothing in
the standard that prevents an implementation's run-time support and
library from providing all required functionality directly on top of
bare hardware.

Also note that there are many operating system/C implementation
combinations that do not provide the entire standard library and thus
are freestanding implementations as defined by the standard despite
the presence of an operating system.
 
D

Dan Pop

In said:
All the ones mentioned are library facilities in the sense of
Introduction#3.

None of them is a library facility in terms of common computing sense.

Furthermore, some of them are not even documented in clause 7, so they
are not library facilities even in the sense of Introduction#3.

For purely *administrative* reasons some headers are documented in
clause 7, along with headers providing access to library facilities.
This doesn't make them library facilities.

Dan
 
D

Dan Pop

In said:
Also note that there are many operating system/C implementation
combinations that do not provide the entire standard library and thus
are freestanding implementations as defined by the standard despite
the presence of an operating system.

Or they are non-conforming hosted implementations. It depends on what
the implementors claims them to be.

A more important note is that the *same* compiler can be part of both
hosted and freestanding implementations. Compare gcc when used to
compile the linux kernel or glibc to gcc when used to compile the
canonical "hello world" program.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top