freestanding program

https://en.cppreference.com/w/c/language/basic_concepts 裡提到
A C program is a sequence of text files (typically header and source files) that contain declarations. They undergo translation to become an executable program, which is executed when the OS calls its main function (unless it is itself the OS or another freestanding program, in which case the entry point is implementation-defined).

freestanding program或是stand-alone program,本身的程式不依靠外部的模組, 通常用在bootstrap loading,因為不依靠外部模組,loader很簡單就直接指到要執行的指令開始跑

在C99規範中,§5.1.2定義了執行環境Execution environments – freestanding、 hosted environment

其中有個重點:
All objects with static storage duration shall be initialized (set to their
initial values) before program startup

Freestanding定義在C99 §5.1.2.1

§5.1.2.1 Freestanding environment 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.

描述例如program startup的entry point是implementation defined,相對於我們一般熟知的main(定義在hosted environment §5.1.2.2.1裡)

This entry was posted in C Language. Bookmark the permalink.

Leave a Reply