| New Reply |
[C]How are library functions implemented? |
Share Thread | Thread Tools |
| Dec13-12, 05:28 AM | #1 |
|
|
[C]How are library functions implemented?
There are several useful library functions that I use while I write C programs. Are these functions also C programs?
Since I use stdio.h library for printf and scanf, how are these functions implemented? |
| Dec13-12, 05:57 AM | #2 |
|
Admin
|
You should be able to find stdio sources just by googling them. Yes, they are implemented in C.
|
| Dec13-12, 06:23 AM | #3 |
|
|
To implement printing and scanning functions you need some commands to communicate with the graphics part of the computer right? Are those commands not taught to a beginner in programming because I never encountered any commands like that yet.
I did try to see the source codes but didn't understand them |
| Dec13-12, 06:44 AM | #4 |
|
Admin
|
[C]How are library functions implemented?printf and scanf don't need to access anything else but a stream from which they read/write data. This can be all done in simple C. At some lower level writing data on the screen or to the disk requires interacting with the hardware itself. This is done through the memory dedicated to the hardware (like video memory) and/or I/O space. Dedicated memory can be accessed from C through pointers, but as far as I know C doesn't define a standard way of accessing I/O space (I can be wrong here) and I/O ports access is done through functions written in assembler (and called from C just like every other function). 20+ years ago I would show you some simple examples that you could run from the DOS command line to see how it works, but these times are long gone. |
| Dec13-12, 09:59 PM | #5 |
|
|
Borek -
If you mean calling BIOS interrupts you can do that on 32 bit x86 Linux using LRMI http://sourceforge.net/projects/lrmi/ With the advent of UEFI (BIOS) and Windows 8 blocking Linux boot without a MS approved key, some Linux desktop folks are rethinking BIOS. http://www.zdnet.com/blog/open-sourc...d-fedora/11187 |
| Dec14-12, 12:03 AM | #6 |
|
|
long ago when i programmed my 68K-based Mac, i drilled down to the Mac Toolbox calls, it was called DrawChar(c) which transferred the bits of the ASCII character c (whereas the font and font size and style were already defined) to the bitmap of the screen and moved the "pen" over to the right to the position for the next char, and that was in assembly. i think putc() for a carriage return moved the "pen" to the left margin and down one line of text. if the stream was to a file or serial port, then other routines were called. |
| Dec14-12, 12:14 AM | #7 |
|
|
|
| Dec14-12, 02:43 AM | #8 |
|
Admin
|
Things got more complicated in the graphics modes. If memory serves me well, it was still possible to call BIOS to make it draw a letter using the standard font, but I am not sure if it was guaranteed to work, and BIOS calls for graphic modes were notoriously slow, so it was much better to do all the work by yourself. That was not easy due to the way VGA memory is organized (EGA was similar, and I never worked with CGA). To draw a single pixel in 16 color mode you had to switch between memory planes, as the information about a pixel was stored in 4 different places. On the one hand that meant a programming nightmare in 16 colors, on the other - people were getting creative and half of the PC demoscene was using these modes to get effects that IBM engineers never dreamed about ![]() In 0x13 mode - 320*200*256 colors - things were pretty easy, one memory plane and linear addressing of the pixels, as they all fit in one 64k bank. That was favorite mode for many applications. But there was also another 256 colors mode, so called x-mode, that used memory planes. Addressing was much more tricky, but it was possible to use other resolutions, double or even triple buffering, and in some cases x-mode was faster, as it allowed writing to all four planes with one instruction. All these things required direct access to the memory and I/O ports. I was doing it in Turbo Pascal at the time. Sadly, when my favorite piece of code made its way to SWAG it didn't bear my name on it (http://webtweakers.com/swag/GRAPHICS/0155.PAS.html ). Perhaps this one: http://webtweakers.com/swag/GRAPHICS/0174.PAS.html shows better the combination of memory and I/O ports access we used at the time. |
| Dec14-12, 03:55 AM | #9 |
|
Recognitions:
|
Even in text mode, there are functions to upload a font (a moderate amount of binary data for all 256 characters) to the screen, and in text mode, you can toggle between 25 line, 43 line, and 50 line modes, each of which uses a different font.
|
| Dec14-12, 05:30 AM | #10 |
|
Admin
|
I can't check details now. 20 years ago I had a thick book about EGA/VGA programming, but it is either somewhere in the cardboard boxes or was just thrown out, as VGA was first replaced by VESA standard, and later Windows and 3d accelerators rendered my knowledge useless. |
| Dec14-12, 12:11 PM | #11 |
Recognitions:
|
|
| New Reply |
| Thread Tools | |
Similar Threads for: [C]How are library functions implemented?
|
||||
| Thread | Forum | Replies | ||
| How big circuits are implemented on small IC... | Engineering Systems & Design | 3 | ||
| Logic Function Being Implemented | Engineering, Comp Sci, & Technology Homework | 2 | ||
| Is DE quadrature implemented in Matlab? | Calculus | 0 | ||
| BitTorrent implemented in Python. | Computing & Technology | 3 | ||
| How is LaTeX implemented on this site? | Math & Science Software | 5 | ||