-3

我知道linux内核源代码是纯c的。所以我想知道如何在不使用 printf api 的情况下用纯 C 编写简单的 Hello, World 程序?

4

2 回答 2

5

I know that linux kernel source is in pure c.

It is most certainly not. The Linux kernal is infamous for the frequent use of non-standard extensions from the GCC compiler.

So I want to know how can I write simple Hello, World program in pure C without using printf api?

printf is just a wrapper around the OS API functions. Do you mean to ask how to write printf using only Linux API functions? Becase "pure C" is defined in the C standard ISO 9899, which has nothing to do with the Linux OS.

于 2013-10-07T06:34:24.410 回答
3

When running in a process in any operating system, you have no direct access to hardware resources. So there's no way to print anything without asking the OS to do it for you.

Instead of printf, you can use a lower level API, such as write.

You can go further and issue a system call yourself, using the right machine instruction (which is OS and architecture dependent). This way you won't use any library, but will still rely on the OS.

于 2013-10-07T06:53:24.267 回答