![]() |
Function header files
Hi,
I am a student of C/C++. One of the mistakes I often make is forgetting to include the appropriate header files for the standard functions I use. Is there an easy way (a website?) to find out where a certain standard function is prototyped in? I can find answers via google search or MSDN library, but it's more time consuming than I'd prefer. Ideally, I would prefer to just go to a website, type in the name of the function in a search box and find out what header file I should include and how it is defined. Thanks for your help! alanxx |
Re: Function header files
On Feb 15, 7:04*pm, alanxx <alanxxi...@gmail.com> wrote:
> Hi, > > I am a student of C/C++. One of the mistakes I often make is forgetting to include the appropriate header files for the standard functions I use. Is there an easy way (a website?) to find out where a certain standard function is prototyped in? I can find answers via google search or MSDN library, but it's more time consuming than I'd prefer. Ideally, I would prefer to just go to a website, type in the name of the function in a search box and find out what header file I should include and how it is defined. Thanks for your help! If you were using a proper *NIX distro I'd say just read the man pages. Google is your friend otherwise. Tom |
Re: Function header files
On 02/16/11 01:04 PM, alanxx wrote:
> Hi, > > I am a student of C/C++. One of the mistakes I often make is forgetting to include the appropriate header files for the standard > functions I use. Is there an easy way (a website?) to find out where a certain standard function is prototyped in? Well there aren't that many to remember! On a Unix or Unix like system, just type man function, for others you could use the search box on the online Unix specification: http://www.opengroup.org/onlinepubs/000095399/ -- Ian Collins |
Re: Function header files
On Feb 15, 6:04*pm, alanxx <alanxxi...@gmail.com> wrote:
> Hi, > > I am a student of C/C++. One of the mistakes I often make is forgetting to include the appropriate header files for the standard functions I use. Is there an easy way (a website?) to find out where a certain standard function is prototyped in? I can find answers via google search or MSDN library, but it's more time consuming than I'd prefer. Ideally, I would prefer to just go to a website, type in the name of the function in a search box and find out what header file I should include and how it is defined. Thanks for your help! > > alanxx Assuming the header files really are files (the standard does not require this), you could do a filesystem search. on unix: grep -d recurse funcname /usr/include on windows there's some kind of FindFile wizard where you can search for files 'Containing text:'. But you may get many spurious results. |
Re: Function header files
alanxx <alanxxiang@gmail.com> writes:
> I am a student of C/C++. Oh, I hope not! If you mean that you're a student of C and of C++, that's fine. The problem is that "C/C++" is often used to refer to a mythical language that's some combination of the two. C and C++ are closely related by quite distinct languages. > One of the mistakes I often make > is forgetting to include the appropriate header files for the > standard functions I use. Is there an easy way (a website?) to > find out where a certain standard function is prototyped in? I > can find answers via google search or MSDN library, but it's more > time consuming than I'd prefer. Ideally, I would prefer to just > go to a website, type in the name of the function in a search > box and find out what header file I should include and how it is > defined. Thanks for your help! Whatever documentation you're using that tells you how to call the function *should* tell you which header you need to include. Does your IDE (if you're using one) provide documentation for standard functions? On Unix-like systems, the man page for each function tells you what you need to include. Try <http://www.linuxmanpages.com/>. (This won't be helpful for MS-specific or Windows-specific functions.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
Re: Function header files
luser- -droog <mijoryx@yahoo.com> writes:
> On Feb 15, 6:04Â*pm, alanxx <alanxxi...@gmail.com> wrote: >> I am a student of C/C++. One of the mistakes I often make is >> forgetting to include the appropriate header files for the >> standard functions I use. Is there an easy way (a website?) to >> find out where a certain standard function is prototyped in? I >> can find answers via google search or MSDN library, but it's >> more time consuming than I'd prefer. Ideally, I would prefer >> to just go to a website, type in the name of the function in a >> search box and find out what header file I should include and >> how it is defined. Thanks for your help! > > Assuming the header files really are files (the standard does not > require this), you could do a filesystem search. > > on unix: > grep -d recurse funcname /usr/include > > on windows there's some kind of FindFile wizard where you can > search for files 'Containing text:'. > > But you may get many spurious results. You almost certainly *will* get spurious results -- lots of them. On my system, for example (Ubuntu 10.04), 28 files under /usr/include that contain the word "fprintf". And the compiler searches 3 directories that aren't even under /usr/include. Read the documentation. System header files are intended to be read by the compiler, not by the programmer. (That's not to say you shouldn't read them; you can learn a lot that way. But keep in mind that the code in system headers needn't be portable, or even necessarily legal C.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
Re: Function header files
pete <pfiland@mindspring.com> writes:
> alanxx wrote: >> Is there an easy way (a website?) >> to find out where a certain standard function is prototyped in? > > Here is a free draft of the next standard: > > http://www.open-std.org/jtc1/sc22/wg...docs/n1547.pdf > > It is easy to use the C standard > to find out where a certain standard function is prototyped in. [...] Nobody implements that version of the standard yet. If your goal is to look up standard functions supported by your compiler, use this draft of the *current* standard: http://www.open-std.org/jtc1/sc22/wg...docs/n1256.pdf (That's a draft of the C99 standard; most compilers don't even *fully* implement that yet.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
Re: Function header files
On Feb 16, 2:04*am, alanxx <alanxxi...@gmail.com> wrote:
> Hi, > > I am a student of C/C++. One of the mistakes I often make is forgetting to include the appropriate header files for the standard functions I use. > If it does input/output stdio.h. If it's a trivial function that works on a string or area of memory, string.h. If it's a mathematical function, math.h. If it's malloc() and family or anything else, stdlib.h. Major exceptions - ctype.h contains is is... macros. assert.h has its own header for some reason. So does time.h. It's a reasonably logical division, though with a few quirks. |
Re: Function header files
Le 16/02/11 01:04, alanxx a écrit :
> Hi, > > I am a student of C/C++. One of the mistakes I often make is forgetting to include the appropriate header files for the standard functions I use. Is there an easy way (a website?) to find out where a certain standard function is prototyped in? I can find answers via google search or MSDN library, but it's more time consuming than I'd prefer. Ideally, I would prefer to just go to a website, type in the name of the function in a search box and find out what header file I should include and how it is defined. Thanks for your help! > > alanxx Hi I am the author of the lcc-win compiler system If you use a decent IDE (under windows) put the cursor under the identifier you want to find out and press F1. At least that is what the IDE of lcc-win does. F1 calls the documentation and the docs tell you which include file is to be used and the library you need to add to the link (if any) But the most portable solution is this. I have built a header called stdheaders.h containing the following text: #include <assert.h> #include <complex.h> #include <ctype.h> #include <fenv.h> #include <float.h> #include <inttypes.h> #include <limits.h> #include <locale.h> #include <math.h> #include <setjmp.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stddef.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <wchar.h> #include <wctype.h> #include <conio.h> #include <malloc.h> #include <process.h> Now I do not ever forget any standard header. Since I use a very fast compiler the extra milliseconds used in parsing those headers have no importance |
Re: Function header files
jacob navia wrote:
> #include <conio.h> "conio.h is a C header file used in old MS-DOS compilers to create text user interfaces. It is not described in The C Programming Language book, and it is not part of the C standard library, ISO C nor is it required by POSIX." Sorry don't take seriously, just couldn't resist :-) -rasp |
| All times are GMT. The time now is 03:26 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.