Is there any way to restrict access to external variable with in a function?
here is a code like:
how we can restrict integer i accesibility within the func1?
extern int i;
func1()
(
}
thanks in advance
Bhupesh....
Printable View
Is there any way to restrict access to external variable with in a function?
here is a code like:
how we can restrict integer i accesibility within the func1?
extern int i;
func1()
(
}
thanks in advance
Bhupesh....
Declare i to be a local variable in func1() instead of a global variable.
Hi Laserlight ...
thanks for reply....but still i dint get that...can u plz pass some more light on this...
Thanks
Bhupesh
The point is that an external variable IS external, so it is available everywhere.
You can put the extern declaration INSIDE a function, e.g.
This of course isn't going to prevent some other function from doing exactly the same, so it's only going to make sure that you KNOW which functions have direct access to the variable.Code:func1()
(
extern int i;
...
}
--
Mats
Sorry for the double post. On top of what I wrote above, there could be any number of OTHER solutions that you could use to restrict the access so that you can only get hold of some "global" data in the right way. You could for example have a local static variable that you return the address of in a particular function - of course, there's still nothing preventing this function from being called from multiple places.
--
Mats