Re: [Dev-C++] globals considered harmful?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-04-30 07:06:05
|
No security leak - the information is stored in the same memory as non-global variables. Its just that it is a bother to keep track of global variables, avoid name-space collision, make sure they have correct values etc. When you encapsulate the data as private in classes, you know that only a couple of methods of that class may change the data, thereby improving the chance of the variables having the correct value. An example: a linked list and a variable storing number of elements in the list. Whenever an element is added or removed from the list, the count variable must also be updated. If the list was global, some other code might insert a new element but forget to update the counter. An other example: How soon do your global variable get the correct value, in case you can't assign the value in the declaration? You have to wait until a specific function is called, but during this time, other code might try to use the global variable. If it is encapsulated, the access methods would know if it has been initialized or not. Third example: in multithreaded environments, every access to the global variable must be protected by a critical section or a mutex or similar, or fatal things can happen to the application. /Per W On 30 Apr 2003, Christian Schaefer wrote: > hi there! > > I wonder if there is any security issue in using global variables? > are they just considered 'un-styleful' or are they a security leak? > > regards > /christian > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |