Pointer to PROTECTED variable

Pointer to PROTECTED variable

I get the following message when I try to point to a PROTECTED variable from outside of the modele where it is defined:

A use associated object that has the PROTECTED attribute shall not appear as a target in a pointer-assignment-stmt

What is the rationale behind disallowing this?

If I declare a pointer in the module where the PROTECED variable is declared, associate this pointer with the PROTECTED variable, and and then associate the original pointer with the one in the module there is no error. However, now the PROTECTion is also lost and I'm able to reassign the value of the PROTECTED variable.
Is this intensional, ie. standard conforming, behavior, or is it a bug?

7 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

The standard says:

C551 A nonpointer object that has the PROTECTED attribute and is accessed by use association shall not appear in a variable definition context or as the data-target or proc-target in a pointer-assignment-stmt.

The idea of PROTECTED is that use outside the module is restricted, but inside the module it is assumed you know what you are doing.

Steve - Intel Developer Support

So if I have a set of objects that I want to be constant but I also want to use them as pointees, what do I do? I cannot use PARAMETERs as they are not even variables...
The important thing is that I dont want to accidentally change their values.

Why must they be pointees? Perhaps what you want is to define some access (get) methods that are exposed from the module without exposing the objects themselves. Once you have a pointer to something, you can change its value.

Steve - Intel Developer Support

Often a get method will get the job done, but sometimes it will cause unnecessary awkwardness and, more often, performance penalty when passing around "constants" that are function result temporaries instead of pointers. I can use pointers to "ordinary" variables, but ideally I'd like to make them read-only for security reasons.

So what about the "security hole" with pointers to pointers to protected variables that I described in the last part of my post? Is this how it is supposed to work?

Yes, that's how it's supposed to work. Within the module, you can do anything you want - and if that's to expose the object through a pointer, then you're free to do that. Since the module is where the PROTECTED attribute was given, it is assumed that the module author knows what they're doing.

And in case you wonder - if you make the pointer itself protected, all that means is that the association status of the pointer can't be changed - it doesn't protect what the pointer points to. This was deliberate and argued at length at standards meetings.

Steve - Intel Developer Support

Thank you so much, Steve!

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!