Mail Archives: djgpp/2000/03/06/16:14:43
Cyberdivad <cyberdivad AT caramail DOT com> wrote:
> Here is an example of source with the project file for rhide. This example
> work only if you don't setup variables with values (like a=2;).
> In this example, this is not really a problem, but my program needs to
> assign values to var in header files.
Then your idea of how C programming works must be wrong. What makes
you think it makes a difference for *you* (or your program), where
that initialization is? In other words, why would your program 'need'
that? It sure does make a difference to the C compiler and linker, as
defined by the programming language inventors, so you'll have to
follow their rules, rather than your personal preferences.
I'll show you how to modify it to get a working C program.
> source of header f.h :
> #include <stdlib.h>
> #include <stdio.h>
> #include "allegro.h"
> #ifndef FONC_H
> #define FONC_H
> // here
Change these two:
> int d_a=10;
> int d_b=11;
into:
extern int d_a;
extern int d_b;
> extern int calcab(int a, int b);
> #endif
> ----------------
> source of f.c :
> #include "fonc.h"
Add two lines, here:
int d_a=10;
int d_b=11;
> int calcab(int a, int b)
> {
> return a*b+d_a;
> }
> --------------
[...]
Once you've checked that it works, now, go back to your C textbook and
read up on how to organize a program into multiple source files.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -