Re: Global variable modifiable by some translation units but not others



"Spiros Bousbouras" <spibou@xxxxxxxxx> writes:

Let's say I have a global variable int var which I want
to be known to translation units T1 and T2, I want T1
to be able to read its value and modify it and T2 to be
able to read its value but not modify it. Would it work
if I declare it inside T1 as "extern int var" and inside T2
as "extern const int var" ?


Any easy way is to not declare it at all in T2 and only give access via a "get"
function declared in T1. Or?
.



Relevant Pages

  • Global variable modifiable by some translation units but not others
    ... to be known to translation units T1 and T2, ... able to read its value but not modify it. ... if I declare it inside T1 as "extern int var" and inside T2 ...
    (comp.lang.c)
  • Re: Property... why?
    ... >>if you want to access and modify your field, declare it as public is more ... that you don't want to modify his value from outside the class. ... Declaring a field as private and accessing with a property is good object ... It enables a class to encapsulate data which it has sole ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Property... why?
    ... >>>if you want to access and modify your field, declare it as public is more ... > there's a contradiction here because declaring your field as private means ... > that you don't want to modify his value from outside the class. ... is because the design time environment relies on ...
    (microsoft.public.dotnet.languages.vb)
  • Re: const int value changing....
    ... >>> If you want to modify an object, don't declare it const. ... >>> declare an object const, ... Solid meets fluid: A constant should not be changed. ...
    (comp.lang.c)
  • Re: Global variable modifiable by some translation units but not others
    ... able to read its value but not modify it. ... if I declare it inside T1 as "extern int var" and inside T2 ... are inconsistent when they appear in different translation units (i.e. ...
    (comp.lang.c)