Re: including files



Eitan M wrote:

Yes,
I have included the *.c files under "source files".

But if the "*.c" program has main function,
program isn't compiled.
(I want to use some functions of the included file, which is not the "main" function, can I just declare the functions I want to use only at the header).

Thanks :)



Eitan:

Declare function in the header:

void f(); // declaration, no definition

Define function in one .c file only:

void f()
{
printf("Hello world\n");
}

Include the header file in the .c file that defines f(), and in every .c file that wants to use it. That way you can be sure that the prototype matches the actual function definition.

What problem are you having?

David Wilkinson
.



Relevant Pages

  • Re: const and standard types
    ... > function definition you declare the value const, ... > void f(const int i) { ...
    (comp.lang.cpp)
  • Re: external variables
    ... Well, if you can't declare a function from within a function, what use is ... the keyword extern going to do you there? ... You can't *define* a function within a function definition: ... void outer{ ...
    (comp.lang.c)
  • Re: external variables
    ... Well, if you can't declare a function from within a function, what use is ... the keyword extern going to do you there? ... You can't *define* a function within a function definition: ... void outer{ ...
    (comp.lang.c)
  • Re: static library problems
    ... Do not declare variables in header files. ... variable itself must be declared in a .cpp file. ... >If i want to use this string in other modules, i just need include the header, i need not link this static lib. ...
    (microsoft.public.vc.mfc)
  • Re: Variables and scope ? !!!!
    ... without seeing the project but i no professional vba programmer but would ... > global -- available to all code in the application, declared in the header ... > a) Declare the variable, in the header of an ordinary module ... Global variables are, in general, bad practice. ...
    (microsoft.public.word.vba.general)