Множественное объявление переменных - C (СИ)
Формулировка задачи:
Поясните, пожалуйста, что я делаю не так.
Я создал хэдер, где объявляю глобал-переменные.
в Си-модули, где задействованы данные переменные, я ставлю Ругается на повторяющиеся переменные.
Причём, если те же самые переменные задать в
#ifndef GLOBALVAR_H_INCLUDED #define GLOBALVAR_H_INCLUDED #define bul u8 //уровни #define lvl_first (1) #define lvl_jaws_boss (2) #define lvl_worm_boss (3) #define lvl_gorguli (4) #define lvl_rotor (5) #define lvl_levi_boss (6) #define lvl_psevdo3d (7) #define lvl_fire (8) #define lvl_baphomet_boss (9) #define lvl_lilith_boss (10) #define lvl_raiders (11) #define lvl_jesus (12) #define lvl_rebro (13) #define lvl_arcanoid (14) #define lvl_behemoth (15) #define lvl_dark (16) //u16 hscroll[225];// = {0}; //scroll values bul init_menu_f=FALSE; bul star_game_f=FALSE; u32 previous ; bul initball_f; char str[16]; bul init_ball_f; u16 palette[64]; u16 ind; int level; bul game_over_f; Sprite sprites[80];// 0-якорь 0-9 цепь, пауки 10- головка червя,ключ 11-27 брызги 28- ракетк0 29- мячЪ 30- головка бафомета 31-огонёк бафомета 32- тело бафомета 30-80- дождь, бульбашки, мухи struct myBall { int x; int y; int dx; int dy; int speed; } bball; int batx; int baty; int batdx; int batspeed; int batcount; int pent_disp; #endif // GLOBALVAR_H_INCLUDED
#include "globalvar.h"
И вот например хочу я в одном из модулей (nexlevel.c
) присвоитьinit_menu_f=FALSE; star_game_f=FALSE;
main.c
, то всё в порядке. И ещё, оно сперва вроде бы компилится без проблем. Но бинарник на выходе не собирается. А когда повторно нажму компиляцию, то билд-лог пишет следующее:-------------- Build: Debug in agressor (compiler: SGDK)--------------- Running command: make.exe -f E:\sgdk112\makefile.gen E:/sgdk112/bin/gcc -BE:/sgdk112/bin -n -T E:/sgdk112/md.ld -nostdlib out/sega.o @out/cmd_ E:/sgdk112/lib/libmd.a E:/sgdk112/lib/libgcc.a -o out/rom.out out/src/arcanoid.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/arcanoid.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/baphomet.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/baphomet.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/behemoth.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/behemoth.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/dark.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/dark.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/fonanimate.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/fonanimate.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/gorguli.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/gorguli.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/jaws.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/jaws.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/jesus.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/jesus.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/leviathan.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/leviathan.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/lighting.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/lighting.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/lilith.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/lilith.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/lyapanimate.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/lyapanimate.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/main.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/main.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/menu.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/menu.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/nextlevel.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/nextlevel.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/raiders.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/raiders.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/rotor.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/rotor.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/tride.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/tride.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here out/src/worm.o:(.bss+0x0): multiple definition of `init_menu_f' out/src/arachnid.o:(.bss+0x0): first defined here out/src/worm.o:(.bss+0x1): multiple definition of `star_game_f' out/src/arachnid.o:(.bss+0x1): first defined here make: *** [out/rom.out] Error 1 Process terminated with status 2 (0 minute(s), 0 second(s)) 0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Решение задачи: «Множественное объявление переменных»
textual
Листинг программы
extern bul init_menu_f; extern bul star_game_f; extern u32 previous; extern bul initball_f; extern char str[16]; ... extern Sprite sprites[80]; extern struct myBall { int x; int y; int dx; int dy; int speed; } bball; ...
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д