naseeam
asked on
Are there any issues with defining inside function body?
In a typical embedded application, assume following constants are defined inside a function body.
This function is called every loop. Can someone see any issues with defining constants inside function body?
const unsigned short M1500ProductID = 23;
const unsigned short M1500dmProductID = 67;
const unsigned short M1200ProductID = 27;
const unsigned short M1200dmProductID = 66;
const unsigned short M750ProductID = 26;
const unsigned short M750dmProductID = 65;
This function is called every loop. Can someone see any issues with defining constants inside function body?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I wasn't using #defind because then I don't know whay data type they are.
If constants are defined inside a function, do you think they go in stack space or in Read Only memory space or both ?
If constants are defined inside a function, do you think they go in stack space or in Read Only memory space or both ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Since they are const, there is no point in assigning them every time you enter the function; so you should make them static const so they get initialized only once. And BTW, as static, they would not be on the stack.
Open in new window
since I'd rather not want to waste any storage space for variables that never change at all.