Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 19th, 2008, 10:44 AM   #1
tyros
Newbie
 
Join Date: Apr 2008
Posts: 2
Rep Power: 0 tyros is on a distinguished road
Question stdio.h what language is it

I m curious abt the header files used in C
i tried reading the code in stdio,h for the function scanf
but i cant understand anything suggest any source for some info regarding this
tyros is offline   Reply With Quote
Old Apr 19th, 2008, 11:15 AM   #2
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 630
Rep Power: 4 Jessehk is on a distinguished road
Re: stdio.h what language is it

Any header files used by C (stdio.h, math.h, stdlib.h, string.h, etc) are all written in C. Where you might be getting confused is that most implementations of the C standard library that I've seen (especially on POSIX systems where there is a lot of added functionality) are extremely complicated.

There are LOTS of macro tricks, compiler tricks (and extensions) and it is generally unreadable.
For example, the character class functions are fairly easy to use:
c Syntax (Toggle Plain Text)
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int main( void ) {
  5. int ch = 'A';
  6.  
  7. /* is ch an alphabetic character? */
  8. if ( isalpha( ch ) )
  9. puts( "\'A\' is alphabetic!" );
  10.  
  11. return 0;
  12. }

But if you check its preprocessed output (with gcc -E in my particular case), you'll see a massive file where the entire contents of the stdio.h file and the ctype.h file (as well as some other stuff that I don't pretend to understand) have been included.

The actual call to isalpha() was replaced with this:

c Syntax (Toggle Plain Text)
  1. int main( void ) {
  2. int ch = 'A';
  3.  
  4.  
  5. if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalpha) )
  6. puts( "\'A\' is alphabetic!" );
  7.  
  8. return 0;
  9. }

I'm pretty sure that the implementation of the character class functions in glibc (the GNU standard C library) is actually a table lookup.

If you think that's bad, try looking at the C++ headers.

EDIT: I should also mention that the definition for functions will not be in the header files. Header files declare functions so that the compiler and linker will be aware of them. The actual source for a function like scanf will likely not be present on your system. Depending on which platform you're on, you can download the source to your C library and find it. It probably won't be easy to find, though.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Apr 19th, 2008, 12:15 PM   #3
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 3 Narue is on a distinguished road
Re: stdio.h what language is it

>suggest any source for some info regarding this
http://www.amazon.com/Standard-Libra.../dp/0131315099

If you'd like, I can also give you a sample implementation for Windows. It's greatly simplified just so that beginners will have an easier time than with vendor quality implementations.
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Old Apr 21st, 2008, 10:12 AM   #4
tyros
Newbie
 
Join Date: Apr 2008
Posts: 2
Rep Power: 0 tyros is on a distinguished road
Re: stdio.h what language is it

thnks a lot ppl
and narue plz giv me tht windows impementation u were talking abt
tyros is offline   Reply With Quote
Old Apr 21st, 2008, 11:15 AM   #5
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 3 Narue is on a distinguished road
Re: stdio.h what language is it

Attached are the source files. Note that all of the standard names that I redefine have been prefixed with 'j' or 'J' to avoid conflicts with your compiler. Other parts of the standard library (such as malloc or the ctype functions) are used as-is with the implementation; I don't redefine them. Finally, I haven't had time to deck out the whole thing with detailed comments and documentation, so you'll have to suffer with the current minimal commenting.

If you don't understand the what, why, or how of any piece of code, feel free to start a thread on it.
Attached Files
File Type: zip jstdio.zip (20.3 KB, 12 views)
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
If you had it to do all over again, which language? peace_of_mind Coder's Corner Lounge 24 Jan 13th, 2008 5:06 PM
The C programming Language (2nd Edition) nnxion Book Reviews 10 Jul 6th, 2007 3:29 PM
Assembly Language DaWei Coder's Corner Lounge 0 Apr 26th, 2007 10:15 PM
Language creation/extending gryfang Project Ideas 43 Jul 20th, 2006 1:42 PM
Language display in program Prm753 C++ 3 May 30th, 2006 5:45 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC