$ nm -f posix helloworld | grep main __libc_start_main@@GLIBC_2.0 U main T 0804b26c 00000153其 prototype 為接受兩或三個 argument 的 int 傳回型態,然而,在相對的 freestanding environment 中,並沒有 Standard Library,而且沒有特定的 entry point,這種特別的情況對 kernel 或 firmware 設計來說,是必要的,一般我們會在 C 語言實做的 kernel 或 firmware 中實做簡化的 C Standard Library,其語意與 C89 / C99 的規範可能會有出入。至於如何區分 hosted 或 freestanding environment 呢?前者,也就是預設的組態下,會定義 __STDC_HOSTED__ 的 macro, 在講求可攜性的 NetBSD 中,其 kernel 很明確指定該 flag,不過這也抑制一些可能出現的警告 (TODO: details),此外,可參考 lkml 的討論 "[PATCH] C undefined behavior fix" [by jtv]、[by Tom Rini],以及 [by Joe Buck]。
C99中,Freestanding environment不規範library,甚至進入點也不一定得叫main(),因此不存在語意上的出入問題。見ISO/IEC C99 Specification, section 5.1.2, 茲節錄如下:
In a freestanding environment (in which C program execution may take place without any
benefit of an operating system), the name and type of the function called at program
startup are implementation-defined. Any library facilities available to a freestanding
program, other than the minimal set required by clause 4, are implementation-defined.
補充,前述的clause 4規範的"minimal set"應該只包含, , , , , , 這幾個header (如果我沒有誤解C99 spec的話)。
由 I-Jui Sung 發表於 June 15, 2006 07:28 PM角括號似乎被濾掉了。前文提及的header如下:
float.h, iso646.h, limits.h, stdarg.h, stdbool.h, stddef.h, and stdint.h