Function header files

A

alanxx

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
 
T

Tom St Denis

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
 
I

Ian Collins

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/
 
L

luser- -droog

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.
 
K

Keith Thompson

alanxx said:
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.)
 
K

Keith Thompson

luser- -droog said:
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.)
 
K

Keith Thompson

pete said:
Here is a free draft of the next standard:

http://www.open-std.org/jtc1/sc22/wg14/www/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/wg14/www/docs/n1256.pdf

(That's a draft of the C99 standard; most compilers don't even
*fully* implement that yet.)
 
M

Malcolm McLean

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.
 
J

jacob navia

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!


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
 
R

Ralph Spitzner

jacob said:
#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
 
M

Malcolm McLean

"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.
 
B

Ben Bacarisse

Malcolm McLean said:
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.
 
I

ImpalerCore

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

The cplusplus.com website might be what you're looking for. If you
type in a function name in the search box, you get a web page of the
function plus its header on the navigation bar to the left.

Hope it helps.
John D.
 
J

jacob navia

Le 16/02/11 13:00, Ralph Spitzner a écrit :
"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

conio.h describes the interface for old Dos functions in lcc-win that
allows you to use the old Borland "gotoxy()" text mode packages and
have text mode with colors and simple "graphics" using special
characters.

If you do not like it you just erase that line. The concept is clear.
 
R

Ralph Spitzner

jacob said:
Le 16/02/11 13:00, Ralph Spitzner a écrit : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If you do not like it you just erase that line. The concept is clear.


Not flaming you here. I just thought of it as being 'funny' finding such
a dinosaur, looking at all the C99 etc. discussion going on here.

-rasp
 
T

Tom St Denis

Le 16/02/11 13:00, Ralph Spitzner a écrit :





conio.h describes the interface for old Dos functions in lcc-win that
allows you to use the old Borland "gotoxy()" text mode packages and
have text mode with colors and simple "graphics" using special
characters.

If you do not like it you just erase that line. The concept is clear.

Along the lines you're talking about it's not uncommon to write a
"project.h" file which includes the relevant header files for the
project. I wouldn't just blindly include all of the headers from /usr/
include mostly because they're not all compatible but also it DOES add
to compile times (hint: think of builds over NFS).

Tom
 
K

Keith Thompson

jacob navia said:
Le 16/02/11 13:00, Ralph Spitzner a ecrit :

conio.h describes the interface for old Dos functions in lcc-win that
allows you to use the old Borland "gotoxy()" text mode packages and
have text mode with colors and simple "graphics" using special
characters.

If you do not like it you just erase that line. The concept is clear.

Fair enough. I suppose there's a similar story for <process.h>.

But why is <malloc.h> in the list? Does it give you something that
<stdlib.h> doesn't?

If you're going to use that approach, perhaps it would be better to have
"stdheader.h" include just the standard headers; if you're using
features from <conio.h> it might be better to emphasize that by
including it directly in your source file.

(Personally I've never done that kind of thing, and it *feels* like
poor style, but I'm not sure I can articulate why.)
 
D

David Resnick

(Personally I've never done that kind of thing, and it *feels* like
poor style, but I'm not sure I can articulate why.)

I'm not sure it is bad "style", but it can certainly cause performance
issues in a large scale build to access/read/parse all the unneeded
header files, particularly if they aren't on a local filesystem.
Certainly, including unneeded headers that might change (standard
headers
don't much in practice) introduces unneeded dependencies into the
build process.
It is vexing if someone touches a file that shouldn't trigger a
global
rebuild of targets but does.

To OP, I'd personally just learn which standard functions go with
which headers.
May take a while, but the C standard library isn't THAT huge...

-David
 
B

Ben Bacarisse

ImpalerCore said:
The cplusplus.com website might be what you're looking for. If you
type in a function name in the search box, you get a web page of the
function plus its header on the navigation bar to the left.

I'd advise against using this site unless you are working in C++.
It works for common C functions but fails for a lot of newer C99
functions.
 
K

Keith Thompson

David Resnick said:
I'm not sure it is bad "style", but it can certainly cause performance
issues in a large scale build to access/read/parse all the unneeded
header files, particularly if they aren't on a local filesystem.
Certainly, including unneeded headers that might change (standard
headers don't much in practice) introduces unneeded dependencies into
the build process. It is vexing if someone touches a file that
shouldn't trigger a global rebuild of targets but does.

For the truly standard headers (those defined by the language
standard), updates shouldn't be much of an issue -- and if the
standard headers provided by the implementation are updated, you
probably *should* recompile everything.

I suppose there's a corner case where you have a "stdheader.h",
and the implementation is updated piecemeal, so an update that
To OP, I'd personally just learn which standard functions go with
which headers. May take a while, but the C standard library isn't
THAT huge...

I tend to agree.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top