c - Is there a meaningful distinction between freestanding and hosted implementations? -
the question have related section four, paragraph six.
the 2 forms of conforming implementation hosted , freestanding. conforming hosted implementation shall accept strictly conforming program.
as understand, constitutes typical application environment, filesystems, allocated memory , threads...
a conforming freestanding implementation shall accept strictly conforming program in use of features specified in library clause (clause 7) confined contents of standard headers
<float.h>
,<iso646.h>
,<limits.h>
,<stdalign.h>
,<stdarg.h>
,<stdbool.h>
,<stddef.h>
,<stdint.h>
, ,<stdnoreturn.h>
.
... , constitutes typical kernel and/or embedded, bare minimum environment doesn't have standard filesystems, allocated memory or threads (among other things).
a conforming implementation may have extensions (including additional library functions), provided not alter behavior of strictly conforming program.
it seems though gives hosted implementation freedom call hosted or freestanding implementation, , when comes filesystems, allocated memory or threads (among other things), these can fall under extension category can merely implement interface returns value indicating errors every time. name few:
fopen
,fgets
,malloc
can returnnull
fprintf
,fscanf
,fputc
,fgetc
can returneof
thrd_create
can returnthrd_error
(indicating "the request not honored")
this implies distinction section four, paragraph 6 gives virtually meaningless. there requirements guaranteeing actual level of functionality these functions in hosted , freestanding implementations? example, required functions above able return other corresponding failure values?
the cited paragraph states quite well.
a hosted execution environment freestanding, not vice versa. compiler need provide freestanding implementation. gcc, example, strictly speaking freestanding only, standard library not included. however, assumes available when compiling hosted environment (the default), assuming lib available on system (like glibc). see here
simply put, freestanding language. not required support libraries , few headers (mostly common types , implementation specific stuff numerical limits, etc.). implies standard library need not exist - nor corresponding headers. reason freestanding environment not have such facilities files, display, etc. used kernels, bare-metal embedded, etc.
note gcc instance will, if compiling hosted environment (-fhosted
), assume functions used in standard library have corresponding meaning , might apply aggressive optimizations (it has many of functions built-in). freestanding, not, can use function strcmp
instance different semantics. however, assumes mem...-functions exist, these used normal code, e.g. struct assignment.
so, if building bare-metal, should pass -ffreestanding
.
if hosted implementation calls freestanding, not hosted implementation anymore. once calls hosted, however, has provide facilities required standard , not allowed implement dummies, has provide semantics defined in standard.
just state clear: cited section allows freestanding environment omit functions of library, except few listed headers. free supply other library , use same names, like. not standard library, there no need compliance.
5.1.2.1 further states "any library facilities available freestanding program, other minimal set required clause 4, implementation-defined.". support statement. sidenote: not require main()
program entry point.
Comments
Post a Comment