PDA

View Full Version : Imagine there's no standard librrary..



Nutshell
01-27-2002, 07:01 PM
HI,

I was wondering if there's no standard library, how many lines of code would it take to do something like printf() ? And is it really possible to program all the functions using the set of C keywords?

doubleanti
01-28-2002, 12:13 AM
// moved... [from the DOS board where nobody but me visites...] i wondered this myself... i'd think not i guess, but can a more knowledgable person respond? thanks!

Yoshi
01-28-2002, 12:14 AM
If you are programming in Windows and don't have windows.h, you need 10,000 lines of code.

QuestionC
01-28-2002, 03:28 AM
Umm.... without a library, you can't hardly do anything. You could sort and search, but that's just about it.

I suppose you could use inline assembly, but that's not C.

That said, printf()... well, if you want to just print a string, then that's less than 100 lines of assembly. If you want it to be able to handle conversion characters and variable length argument lists, then you're looking at something of a monster.

Stoned_Coder
01-28-2002, 08:45 AM
gcc is an open source compiler. Look at the source yourself to see how things are done. A lot of the standard functions are incredibly simple.

Unregistered
01-28-2002, 11:22 AM
I can tell you from first-hand experience of OS development that it is possible to program most of the libc (the standard C library) in 100% C.

There are some functions that you must use inline assembly (such as the port I/O routines), but for the most part C can be used.

And just for the record, printf() can and is (at least in my OS) programmed entirely in <100 lines of pure C (no inline assembly whatsoever).

I hope that scratches your itch. ;) :)

Hillbillie
01-28-2002, 11:26 AM
>then that's less than 100 lines of assembly<

It's less than 15 lines of C, my friend. :)

>If you want it to be able to handle conversion characters and variable length argument lists, then you're looking at something of a monster.<

Not really. A stripped version of printf() can be programmed in a couple of lines of C (okay more than a couple) and a header.

For the few of you whom are overly interested in the libc and printf() and implementing these, you can check out this page:

http://www.execpc.com/~geezer/osd/libc/index.htm