Search code examples
cc11c17

Is there a standard way to prohibit reading (via assignment) of a variable?


It is known and useful features that:

  • const type qualifier prohibits writing (modification) of a variable
  • register storage-class specifier prohibits taking address of a variable

However, is there a standard way to prohibit reading (via assignment) of a variable?

For example, for such variable only writing and/or taking address is permitted.

Reason of the question: need to conditionally prohibit reading (via assignment) of some variable. Does the language provide any way to do it? If no, then why?

UPD. Readers may be interested as well: C: check at compile time or at run time that variable has static storage-class specifier.


Solution

  • No, not as far as I know.

    I don't know why, one reason might be that it's something that is only fantastically rarely useful. You (in my opinion) don't actually explain why you want this, which further emphasizes that's a rather convoluted/weird thing to want.