directly to access globle var or to call a globle function to access the var?

in real-time system, when a function need to access a var which defined in other file,how to do is best,directly to access globle var or to call a globle fun to access the var? according to the OOB methode, i prefer to the latter. but in real-time...? thanks!

Reply to
yaoxinwen
Loading thread data ...

[Please, that word spells itself "global".]

Like almost all questions of the type "what is the best ...?" tend to be, this is impossible to answer more specifically than by the classic catch-all answer: "It depends."

Each way of doing that has its own advandatages and disadvantages. Which outweighs the other depends on the specifics of your problem.

Hmm.. What "OO" thing is OOB?

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

In C you probably need to make the variable external. You may be able to play some tricks so that it's defined as constant to the outside world, yet is defined as normal to the file that changes it. Also, you can always wrap it with a define that _looks_ like a function so that you can change it later (and have the 99 lines of code that use the define still work, while the one that doesn't will break in the field some day).

When I do this sort of thing in C++ I seem to end up making a few objects global, and talking to them using accessor functions. Because you can only talk to the objects with accessors you reduce many difficulties with creative variable use that crop up when you're using C. Because you're making entire objects variable you can cut down on the number of different names flying around.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Posting from Google?  See http://cfaj.freeshell.org/google/
Reply to
Tim Wescott

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.