Where can I find source code to to 'truly' understand what the standard functions are doing in stdio.h? [closed]

孤街浪徒 提交于 2020-01-02 18:25:43

问题


As a newb, like myself, to have great difficulty with searching the header files such as stdio.h for a function like getchar(). Somehow I picked up some information somewhere that I should not be afraid when looking in header files to "see how things work." (C++ Primer Plus, Stephen Prata)

I am very inexperienced with header files to say the least, and programmig in general.

In my attempt to find getchar() I found that stdio.h simply branches to more and more headers, and locating getchar() became increasinly complicated and time consuming, and I never found it. Clearly I am going about this all wrong, my intention was merely to find some source code for functions I am using.

My question therefore is: Where can I find source code to truly 'understand' what the standard functions are 'really' doing?


回答1:


If you're looking for the declarations for variable order or other usage notes, just use an online reference or man.


If you're looking for the actual code, look into an implementation of the C standard library, like GNU's libc.

It's worth noting though, that implementations are not simple, and their graph of dependencies goes far and wide. They also tend to interact with the machine on a lower level than most of us are used to.

Consider libc's implementation of getchar:

int
getchar ()
{
  int result;
  _IO_acquire_lock (_IO_stdin);
  result = _IO_getc_unlocked (_IO_stdin);
  _IO_release_lock (_IO_stdin);
  return result;
} 

Probably not what you were expecting :).

(Note: No idea how good of reference that is for C -- it's just the one I typically use for C++.)




回答2:


you shouldn't search the header files, you should use the man pages or MSDN help.




回答3:


The C Standard does not mandate the standard headers files (like stdio.h) to physically exist. They can be just built-in.

If you don't know the parameters or the return value of a function, read the C Standard or the man pages.




回答4:


In C header files are used (included) to pre declare functions. The functions that are predeclared may either be your own, where the implementation is in another (or the same for that matter) .c file, or an already compiled library. The stdio.h is an example of the last.

You should not have to look in the header file to find the function declaration. try using google typing 'man '

cheers




回答5:


That is kinda like modifying the executable file explorer.exe to perform a simple action in Windows. Those are the base files, leave them be and write your functionality directly in your files. Also, if searching and altering files is an issue, make sure that you are using an IDE and not trying to do things by hand through notepad or another program like that.



来源:https://stackoverflow.com/questions/13350231/where-can-i-find-source-code-to-to-truly-understand-what-the-standard-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!