variable scope, sort of
Displaying 1-8 of 8 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
locke

Quicky one.

If I do an include, can I use global variables from the included file throughout the program?

Example:


--{ system.vc }-----

#include 'house.vc'

void paint_house(int color) {
house_color = color;
}

------------------

--{ house.vc }------

int house_color;

------------------


Also... does that work for defines as well?

-l

EDIT: ick. Sorry about the multi-multi-multi line code block. It seems to be inserting extra BRs...?

Posted on 2004-10-04 14:34:58 (last edited on 2004-10-04 14:36:40)

Rysen

As far as I know that should be fine. I use both globals and #defines in included files without any problems.

Posted on 2004-10-04 17:09:52

rpgking

A global variable will work in any file no matter where it is.

#defines are a bit different though. They work in the file that they're defined in as well as any file included after that constant is defined.

So if you had some file that looked like this:

#include 'something.vc'

#define APPLES 10
#define ORANGES 20
#define PEARS 30

int number_of_apples = APPLES; //obviously works

#include 'something_else.vc'


If 'something.vc' contained this code:

...
int number_of_oranges = ORANGES; //ERROR!!
...


You would get a compilation error because ORANGES would be an undefined constant, since 'something.vc' was included before the constant ORANGE was defined.

If 'something_else.vc' contained this code:

...
int number_of_pears = PEARS; //perfectly valid
...


number_of_pears would be able to be set to PEARS as expected and everything would compile fine because 'something_else.vc' was included after the definition of PEARS.

Hope that helped.

BTW, that multi-line thing with the pre tag happens because you're either using Mozilla or Netscape.

Posted on 2004-10-04 18:41:47 (last edited on 2004-10-04 18:49:59)

locke

Ahh.... yes.

Thank you. I've been working with a scripting language for the past few weeks that acts a bit differently. The includes are all pulled first, then all the defines, THEN it goes through and looks at the code. It's a mess.

Anyway, thanks again.

re: browsers: I'm using Safari, so it's broken there too. Perhaps anything thats not IE?

-l

Posted on 2004-10-04 21:00:33

Omni

Mozilla/Firefox are good.

Posted on 2004-10-05 01:05:47

rpgking

[post deleted...I was confused >_>]

Posted on 2004-10-05 01:20:52 (last edited on 2004-10-05 01:25:12)

Zip

Nah, Omni, same problem in Firefox too (though some of the other non-IE bugs on the website have been fixed now). If you look at the code you post, there's an extra < br > on each line. But, either you don't or have a monitor so big it doesn't matter, as your < pre > tags always span so wide they make my monitor cry...

Zip

Posted on 2004-10-05 01:21:35

Omni

Er...sorry about that.

I threw the extra < br > tags up for bad forum compatibility with Firefox, but eventually I got used to it.

The really wide monitor span can probably be attributed to the 1680 horizontal resolution of my laptop...large enough to be too wide, but not small enough to where I just work in a comfortable sized window.

Posted on 2004-10-05 17:39:09 (last edited on 2004-10-05 17:39:25)


Displaying 1-8 of 8 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.