13.07.2015 Views

A Linguagem C Introdução a Programação em Linguagem C ...

A Linguagem C Introdução a Programação em Linguagem C ...

A Linguagem C Introdução a Programação em Linguagem C ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

imprime_modulo_1();imprime_modulo_2();}getchar();return 0;#ifndef ___GLOBAL___H__#define ___GLOBAL___H__#define GLOBAL 0global.h//variaveis globais definidas <strong>em</strong> main.c e modulo_2.c//use o prefixo g_ para indicar variavel global.extern int g_variavel_do_modulo_2;extern int g_variavel_da_main;//IMPORTANTE//Nao é aconselhado a definição de variavel global no arquivo .h pois//pod<strong>em</strong> haver definicoes multiplas desta variavel <strong>em</strong> varios arquivos.//Use extern, como no ex<strong>em</strong>plo de cima.//int variavel_global = 4; //NAO USE#endif#ifndef ___MODULO__1__H__#define ___MODULO__1__H__#include "modulo_2.h"#include "global.h"modulo_1.hvoid imprime_modulo_1();#endif#include "modulo_1.h"#include void imprime_modulo_1(){printf("\nModulo 1. A variavel_do_modulo_2 vale %d", g_variavel_do_modulo_2);printf("\nModulo 1. A variavel_da_main vale %d", g_variavel_da_main);}#ifndef ___MODULO__2__H__#define ___MODULO__2__H__modulo_1.c#include "global.h"#include "modulo_1.h"void imprime_modulo_2();modulo_2.h#endif#include "modulo_2.h"#include int g_variavel_do_modulo_2 = 10;modulo_2.c

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!