Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Are Global Variables right for me?

Status
Not open for further replies.

moryoav

Computer
Joined
Nov 22, 2005
Messages
4
Location
IL
Hi,

I'm writing a rather large mass of code here with many many functions all need to use a struct filled with data.

What is the best way to access this struct from all the functions?

- As a Global variable.
- As a getappdata/setappdata to be attached to some main object.
- As the figure's 'UserData', to be accessed with get/set.


Thank you.
Y.
 
Since you said "access" and I took that to mean read only, then why not the SW eng way and pass it each time as a formal parameter? If a function needs to modify it, then you coudl return the struct or just the little piece you hanged and have your calling function insert it into the struct. That way you have the option to make mex files on a case by case basis without restructuring your code.
 
Passing the parameter around won't be easy because it needs to be used from various functions that are called as button press callbacks. However, you gave me something to think about. I'll see how this can be adjusted. You're right that this will be the best way to do it.

Thank you.

Y.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top