1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

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

Discussion in 'Embedded' started by yaoxinwen, Mar 1, 2006.

  1. yaoxinwen

    yaoxinwen Guest

    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
    yaoxinwen, Mar 1, 2006
    1. Advertisements

  2. [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, Mar 1, 2006
    1. Advertisements

  3. yaoxinwen

    Tim Wescott Guest

    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

    Posting from Google? See http://cfaj.freeshell.org/google/
    Tim Wescott, Mar 1, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.