Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.c

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-15-2011, 11:04 PM
alanxx
Guest
 
Posts: n/a
Default 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 functionis 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 justgo to a website, type in the name of the function in a search box and findout what header file I should include and how it is defined. Thanks for your help!

alanxx
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 02-15-2011, 11:23 PM
Tom St Denis
Guest
 
Posts: n/a
Default 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. Isthere 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
Reply With Quote
  #3 (permalink)  
Old 02-15-2011, 11:24 PM
Ian Collins
Guest
 
Posts: n/a
Default 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
Reply With Quote
  #4 (permalink)  
Old 02-15-2011, 11:56 PM
luser- -droog
Guest
 
Posts: n/a
Default 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. Isthere 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.
Reply With Quote
  #5 (permalink)  
Old 02-16-2011, 12:48 AM
Keith Thompson
Guest
 
Posts: n/a
Default 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"
Reply With Quote
  #6 (permalink)  
Old 02-16-2011, 12:58 AM
Keith Thompson
Guest
 
Posts: n/a
Default 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"
Reply With Quote
  #7 (permalink)  
Old 02-16-2011, 01:27 AM
Sherm Pendley
Guest
 
Posts: n/a
Default Re: Function header files

Tom St Denis <tom@iahu.ca> writes:

> On Feb 15, 7:04Â*pm, alanxx <alanxxi...@gmail.com> wrote:
>>
>> Is there an easy way (a website?) to find out where a certain standard
>> function is prototyped in?

>
> If you were using a proper *NIX distro I'd say just read the man
> pages.


Seconded. Or a reference book - O'Reilly & Associates' "Nutshell" series
of references is usually quite handy.

sherm--

--
Sherm Pendley
<http://camelbones.sourceforge.net>
Cocoa Developer
Reply With Quote
  #8 (permalink)  
Old 02-16-2011, 02:46 AM
pete
Guest
 
Posts: n/a
Default Re: Function header files

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.

Suppose you want to find where qsort is prototyped;
you search for "qsort" and then you find this:

7.22.5.2 The qsort function
Synopsis
1 #include <stdlib.h>
void qsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));

and that tells you that <stdlib.h>, is the header of interest.

--
pete
Reply With Quote
  #9 (permalink)  
Old 02-16-2011, 03:15 AM
Keith Thompson
Guest
 
Posts: n/a
Default 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"
Reply With Quote
  #10 (permalink)  
Old 02-16-2011, 06:33 AM
Malcolm McLean
Guest
 
Posts: n/a
Default 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.

Reply With Quote
  #11 (permalink)  
Old 02-16-2011, 08:33 AM
jacob navia
Guest
 
Posts: n/a
Default 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
Reply With Quote
  #12 (permalink)  
Old 02-16-2011, 11:00 AM
Ralph Spitzner
Guest
 
Posts: n/a
Default 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


Reply With Quote
  #13 (permalink)  
Old 02-16-2011, 11:43 AM
Malcolm McLean
Guest
 
Posts: n/a
Default Re: Function header files

On Feb 16, 2:00*pm, Ralph Spitzner <r...@spitzner.org> wrote:
> 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
>

He's got malloc.h in there as well, which is another DOS-ism.

Reply With Quote
  #14 (permalink)  
Old 02-16-2011, 11:49 AM
Ben Bacarisse
Guest
 
Posts: n/a
Default Re: Function header files

Malcolm McLean <malcolm.mclean5@btinternet.com> writes:

> On Feb 16, 2:04Â*am, 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.
>>

> If it does input/output stdio.h.


There are a lot of IO function not declared there. wchar.h declares all
the "wide" IO functions.

> If it's a trivial function that works
> on a string or area of memory, string.h.


Except for those that operate on wide or multi-byte strings.

> If it's a mathematical
> function, math.h.


Except for the type generic maths functions declared in tgmath.h and all
the complex mathematical functions declared in complex.h.

> If it's malloc() and family or anything else,
> stdlib.h. Major exceptions - ctype.h contains [the] is... macros.


And wctype.h declares the isw... functions. By the way, what you call
the is... macros must be functions, though they can be macros as well.

> assert.h has its own header for some reason. So does time.h.


And there is also stdint.h, inttypes.h, bool.h, complex.h, float.h,
errno.h, setjmp.h, signal.h, stdarg.h, locale.h and fenv.h (and that's
not all of them).

> It's a reasonably logical division, though with a few quirks.


Unfortunately the logic requires some knowledge of the history. For
example the wide IO and string functions are separate because they are
new.

My point is not to enumerate the errors in your classification but to
show that your general point -- which seems to be that it's not too hard
to remember -- is not really true anymore.

--
Ben.
Reply With Quote
  #15 (permalink)  
Old 02-16-2011, 12:10 PM
pete
Guest
 
Posts: n/a
Default Re: Function header files

Ben Bacarisse wrote:
>
> Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
>
> > On Feb 16, 2:04Â am, 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.
> >>

> > If it does input/output stdio.h.

>
> There are a lot of IO function not declared there.
> wchar.h declares all the "wide" IO functions.


Also,
<stdio.h> is insufficient for using
any of the stdio functions which have names starting
with the letter 'v', such as vfprintf.

<stdarg.h> must be #included too, to use those functions.

--
pete
Reply With Quote
 
Reply

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 03:05 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.