Re: [C] Libraries and headers
From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 07/25/04
- Next message: Alwyn: "Re: List container passed as a reference"
- Previous message: .:'DevarajA':.: "[C] Libraries and headers"
- In reply to: .:'DevarajA':.: "[C] Libraries and headers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Alwyn: "Re: List container passed as a reference"
- Previous message: .:'DevarajA':.: "[C] Libraries and headers"
- In reply to: .:'DevarajA':.: "[C] Libraries and headers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|