What is a good solution to prevent duplicate variables?

Status
Not open for further replies.

jani12

Advanced Member level 4
Joined
Oct 30, 2014
Messages
108
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,298
Activity points
2,536
Our language is embedded 'C'.

We have global static unsigned int variable called vehicle_speed. A lower level function is called to fetch vehicle speed and assign to this variable.

We are adding a new software module that also needs vehicle speed. In a new file, I can create another global static unsigned int variable called vehicle_speed_motor2. Then, I call same low level function to fetch vehicle speed and assign it to vehicle_speed_motor2.

To avoid Two variables, I can create global variable but we think that would be too visible.

Are there any other solutions?
 

First solution - use structures.
Second - limit scope of variables.
Third - use pointers.
Fourth - use enumirated array
and e.t.c.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…