Re: [C] Libraries and headers

From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 07/25/04


Date: Sun, 25 Jul 2004 11:25:27 +0100

In article <FGLMc.48708$5D1.2267413@news4.tin.it>, .:'DevarajA':.
<no@spam.com> wrote:

> I'm learning C by myself, and I had some problems finding info about
> libraries and h files. This is what I understood, please correct me if it's
> wrong.
>
> 1) Libraries are files containing one or more object files which include the
> compiled code of library functions such as printf, scanf, pow, etc...

Correct. Users can also write their own libraries.

> 2) Headers contain prototypes (can anyone explain me what are prototypes?)

Function declarations. They show what arguments a function takes and
what, if anything it returns. In standard C, the compiler wants to know
what a function looks like before it can be called.

> of the functions present in the library. H files also contain global
> variables declarations, templates, constants and macros.

I would only put global variables in header files if they were declared
'extern', like this:

extern int MyGlobal;

Then in some .c file, I would have the actual definition of MyGlobal:

int MyGlobal = 42;

Every .c file that includes that header will now be able to 'see'
MyGlobal and use it
.
> 3) The C file that should use one of the functions of the library must
> include the h file coming with it.

Correct. Users can always write their own header files, of course,
which include the prototypes of the functions they write themselves,
constants, extern globals etc.

Alwyn



Relevant Pages

  • Re: where is wininet.lib coming from?
    ... my own CEC file to compile and include custom drivers in an image. ... some reading on the SDK about how to include additional files in an SDK. ... Library files are not associated with header files. ... > libraries to be in the image. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: sources/Build.exe alternate source file location question
    ... >> either compile the individual source modules or also use libraries. ... >Yes, well, there are also shared header files, which can't be compiled ... Header file paths are not a problem. ... >> code base out as a separate module under your SCMS, and share it out of the ...
    (microsoft.public.development.device.drivers)
  • Re: sources/Build.exe alternate source file location question
    ... >> either compile the individual source modules or also use libraries. ... >Yes, well, there are also shared header files, which can't be compiled ... Header file paths are not a problem. ... >> code base out as a separate module under your SCMS, and share it out of the ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Linker error - fooView.obj LNK2005: _IID_IProvideTaskPage already defined in fooDoc.obj
    ... declarations, one in the document and one in the view. ... multithreaded libraries would refer to symbols in the single-threaded and multithreaded ... Unless someone in the header files is ... Look for simple solutions first. ...
    (microsoft.public.vc.mfc)
  • Re: Borland C++BuilderX
    ... Mostly, programmers do not worry about the contents of header files, ... the rest of the source code that I provide but use the full name when I ... The next two lines of our program are instructions to the compiler to ... object code files and libraries. ...
    (alt.comp.lang.learn.c-cpp)