[Dev-C++] RES: Programming with multiple modules/files
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <and...@su...> - 2007-10-14 17:35:53
|
Thank you!
But, I forgot to tell that:
The "other.c"-type files also make
references to the global variables and
they also call functions that belong to
other "other.c"-type files.
In other words:
///main.c///////
#include "global.h"
main()
{
func_1();
a = 100;
func_2();
func_3()
...
}
///module1.c///////
extern int a;
extern int b;
extern int c;
func_1()
{
a=300;
...
}
///module2.c///////
extern int a;
extern int b;
extern int c;
extern func_1();
func_2()
{
a=300;
func_1(); // see this!
...
}
///module3.c///////
extern int a;
extern int b;
extern int c;
extern func_1();
func_3()
{
a=300;
func_1(); // see this!
...
}
///global.h///////
int a;
int b;
int c;
void func_1(void);
void func_2(void);
void func_3(void);
/////////////
Yes, I could improve the flexiblity of these functions
using parameter-passing. But, is there anything that I
can do to avoid these "extern" declarations in the modules?
Regards
Andre
-----Mensagem original-----
De: Per Westermark [mailto:pw...@ia...]
Enviada em: sábado, 13 de outubro de 2007 09:33
Para: André Macário Barros
Cc: dev...@li...
Assunto: Re: [Dev-C++] Programming with multiple modules/files
//global.h
#ifndef _GLOBAL_H
#define _GLOBAL_H
#ifdef MAIN
#define EXTERN
#else
#define EXTERN extern
#endif
EXTERN int a;
EXTERN int b;
...
#endif // _GLOBAL_H
// main.c
#define MAIN // Want all global variables in this file.
#include "global.h"
int main(void) {
...
}
// other.c
#include "global.h" // Get info about all global variables
/pwm
On Sat, 13 Oct 2007, André Macário Barros wrote:
> Dear users,
>
> Please consider the following project-file
> cenario:
> ///file1.c///////
> #include "global.h"
> main()
> {
> func_x();
> a = 100;
> ...
> }
> ///file2.c///////
> extern int a;
> func_x()
> {
> ...
> a=300;
> }
> ///global.h///////
> int a;
> void func_x(void);
> ///////////
>
> My problem is:
> 1) I have a lot of file2.c-type files (files with only
> function definitions), a lot of functions
> and several "extern" variable declarations;
> 2) Trying to include global.h in file2.c too, avoids
> the need of declaring all extern variables. But this
> action generates warnings of duplicate includes (2 or
> more include global.h);
> My question is:
> Is there any way to manipulate several file2.c-type files
> without declaring each extern variable?
>
> Regards
> Andre Barros
>
>
>
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.488 / Virus Database: 269.14.9/1068 - Release Date:
13/10/2007
> 10:15
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.9/1068 - Release Date: 13/10/2007
10:15
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.10/1070 - Release Date: 14/10/2007
09:22
|