ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The standard C library in general, and printf() in particular, require considerable runtime support - runtime support you more or less take for granted in the user environment - and that simply doesn't exist in kernel mode.
If you have the Rubini/Corbet text, please re-read Chap 2, especially the section "Doing It in User Space". Bear in mind that even a simple "malloc()" (which the "printf()" implementation makes liberal use of!) cannot be done in kernel mode (although there is, to be sure, an anologous "kmalloc()").
Please let me know specifically what you're unclear about - I'd be happy to help clarify.
why we can't use whichever library when we code a linux driver?
we can use strcpy but we can't use printf[/B]
A quote from Robert Love's book: "Linux Kernel Development" (Sams publishing):
[quote]Unlike a user-space application, the kernel is not linked against the standard C library (or any other library, for that matter). There are multiple reasons for this, including some chicken and egg situations, but the primary reason is speed and size.[quote]
Your book is correct that the kernel is not linked against the standard C library ... and, in fact, *cannot* be linked against it.
I'm not sure I completely agree with the "speed and size" arguments (although obviously both are an important consideration in *any* code - especially in systems code).
The "chicken and egg" argument is absolutely correct: the kernel is there to provide exactly that infrastructure that the standard library needs (like the ability to "malloc()" paged memory, for example). It cannot easily provide that infrastructure and at the same time use it.
But, IMHO, the main point is that kernel code (in the executive context) and non-kernel code (in user context) are simply two very different, in many ways incompatible environments.
Another good (albeit totally non-Linux ;-)) book that os2 might find useful is:
"Inside Windows 2000", Solomon/Russinovich, Chap 1, pp 9-13, "Kernel mode vs. user mode".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.