Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 12th, 2005, 2:49 AM   #1
robert_sun
Newbie
 
Join Date: Sep 2004
Posts: 6
Rep Power: 0 robert_sun is on a distinguished road
Unhappy variable problem

Can anybody help me on this problem:

I am writing a simulation program with several files. In a header file, I declared e global variable in hope that all other files could use it. so i put down: #define size 100 int memory[size]; in the header file memory.h. However, there are two seperate C files using that variable: simulation.c and processor.c. When I run the program, simulation.c did load all the stuff in the variable memory[size]; but when the program reaches to functions from processor.c, all the loaded stuff in variable memory[size] lost, as if the function in processor.c actually reinitialised the variable. I checked everywhere in processor.c, don't see anywhere the function can initialise the variable. I also tryed to add 'extern' in front of the definition, but end up with compiling error:
Error: Unresolved external '_memory' referenced from C:\DOCUMENTS AND SETTINGS\RS1249\CBPROJECT\SIMULATOR\WINDOWS\DEBUG_BUILD\SIMULATOR.OBJ

I don't know what to do now. Please can somebody help me on this. Thanks
robert_sun is offline   Reply With Quote
Old Apr 12th, 2005, 2:10 PM   #2
brkstf
Programmer
 
brkstf's Avatar
 
Join Date: Feb 2005
Posts: 89
Rep Power: 4 brkstf is on a distinguished road
define statements only tell the pre-processor to substitute one text string for another. you have declared it wrong.

to make something truly global, declare it BEFORE main, outside of any braces. and declare it in your driver/application file, not a library.

it's a bad idea, though. it's best to just pass the address through a function call.
brkstf is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC