What address clause for a GNAT.Sockets.Selector_Type

Viewed 87

I'm using a Selector_Type in my code.

On one hand, the Selector_Type from GNAT.Sockets comes with the pragma:

pragma Volatile (Selector_Type);

On the other hand, Gnatckeck's rule 9.1.1.2 applied to my code will raise

volatile object with no address clause [Volatile_Objects_Without_Address_Clauses]

because of the pragma.

This topic isn't handled in wikibook's example nor do I address this issue anywhere in my base code.

So, what address should I use for my selector?

1 Answers

You can’t. The Selector_Type is volatile because it’s an interface to the operating system, and may (will) change without any action on the part of the Ada code.

My trial example was

package Rules is
   type Selector is limited private;
private
   type Selector is null record with Volatile;
   S : Selector;
end Rules;

checked as

$ gnatcheck --show-rule rules.ads -rules +RVolatile_Objects_Without_Address_Clauses
rules.ads:5:04: volatile object with no address clause [Volatile_Objects_Without_Address_Clauses]

It seems that you have to say what rules you want checked, why not just don’t select this one?

Alternatively, if you have control of the source, you can apply an exemption.

In this case, this would look like

package Rules is
   type Selector is limited private;
private
   type Selector is null record with Volatile;
   pragma Annotate (Gnatcheck, Exempt_On,
                    "Volatile_Objects_Without_Address_Clauses",
                    "only a demo!");
   S : Selector;
   pragma Annotate (Gnatcheck, Exempt_Off,
                    "Volatile_Objects_Without_Address_Clauses");
   T : Selector;
end Rules;

and now it checks as

$ gnatcheck --show-rule rules.ads -rules +RVolatile_Objects_Without_Address_Clauses
rules.ads:11:04: volatile object with no address clause [Volatile_Objects_Without_Address_Clauses]

(line 11 is T's unexempted declaration; no complaint about S's declaration on line 8).


Note:

Apologies for earlier versions of this answer, which had a fundamental misunderstanding. gnatcheck supports the rule just fine, so long as you read it properly: it’s about volatile objects with no address clause, not volatile types.

Related