Similar Threads:
1.Why constructing functions is a mess [was Language lawyer question: task activation (was: Language lawyer question: task activation))
2.Language lawyer question: Limited Views
On Dec 31 2008, 9:59 am, Maxim Reznik < XXXX@XXXXX.COM > wrote:
> Consider
> package Pkg is
> type T;
> type T is null record;
> end Pkg;
>
> According to 10.1.1(12.3/2)
> "The limited view of a package contains: ... For each type_declaration
> in the visible part, an incomplete view of the type..."
>
> limited view for it would be:
>
> package limited view Pkg is
> type T; -- for declaration type T;
> type T; -- for declaration type T is null record;
> end Pkg;
>
> Why two implicit declaration of T are allowed here?
> Is second "type T;" completion for first?
I suppose the answer is that the RM says that the implicit declaration
of the limited view contains an "incomplete view" of a type, not an
actual "type declaration", so the syntax rules having to do with
declarations don't actually apply since these are not really
declarations. In any case, I wouldn't worry about it; the limited
view contains an incomplete view of T. I'm someone who worries a lot
about the tiniest potential ambiguities in the RM, but even this one
doesn't concern me at all.
-- Adam
3.Language lawyer question: Equality on 'Access attributes
Given this code:
package Pak1 is
type Ptr1 is access all Integer;
X : aliased Integer;
Y : aliased Integer;
B : Boolean := X'Access = Y'Access;
end Pak1;
GNAT gives me this error: "two access attributes cannot be compared
directly / they must be converted to an explicit type for comparison".
But I can't figure out why this should be an error. Based on my
understanding of the language: The compiler needs to figure out
whether the interpretation of "X'Access = Y'Access" in which "="
denotes the equality operator implicitly defined for Ptr1 is an
acceptable interpretation (8.6(10-14)). For a call to this "="
function, 6.4.1(3) says that the expected type for each argument is
Ptr1. According to 3.10.2, X'Access and Y'Access do not have a
particular type out of context, but rather the types of these
constructs are determined by the expected type; when determining
whether these can be used as parameters to "=", the expected type is
Ptr1, and clearly it's legal to use X'Access or Y'Access in a
construct where the expected type is Ptr1. So as far as I can tell,
this *is* an acceptable interpretation; and since there's only one "="
visible whose parameter types are access-to-integer, the requirement
of 8.6(30) is met that there be exactly one acceptable interpretation
of the function call, and thus this should be legal. (If there were a
second access type, "type Ptr2 is access all integer", then B's
initialization expression would be ambiguous, since there would then
be two visible "=" operators for which the interpretation would be
acceptable.) Note that the modified version of 3.10.2(2) in
AI95-00235 doesn't affect this analysis.
Is this analysis correct? If not, where did I go wrong? If I'm wrong
and GNAT is right, then could someone explain to me just how 8.6 and
3.10.2 are to be applied together when an 'Access attribute is used?
The wording of the GNAT error message makes it appear to me that
GNAT's authors interpreted the RM as prohibiting this construct---but
I can't figure out where in the RM this would be prohibited.
-- thanks, Adam
4.Why constructing functions is a mess [was Language lawyer question: task activation
Dmitry A. Kazakov wrote:
> Topic: large system design, information hiding:
>
> type T (<>) is abstract tagged limited private;
> private
> type T (...constraints...) is abstract tagged limited record
> ...
> end record;
>
> In order to be used in
>
> type S is new T with ...;
> function Create (....) return S;
How/Why should this derivation be possible? (Deriving publicly
from an abstract limited type with unknown discriminants--to me,
the <> signals the intent of the author of T, namely that T
should be considered none of our business?)
> Remember? Constructor is not function. It never will. See the problem?
Assuming C++ has constructors, will your arguments apply
in the following examples (just trying to understand):
class T
{
public:
virtual void op() = 0;
private:
T(char constraint) : c(constraint) {}
char c;
};
class S : public T
{
public:
S() {}
};
(Note: no suitable default constructor in T)
5.Language lawyer question: task activation
Should this program deadlock? I don't think it should (and I think it
should display "E1 accepted"), based on my understanding about when
task activation is supposed to occur for the function result. But
perhaps there's something about the relation between task activation
and masters that I don't understand. Anyway, this hangs when I
compile it with GNAT and run it---is this correct or not?
-- thanks, Adam
with Text_IO;
procedure Test is
task type TType is
entry E1;
end TType;
task body TType is
begin
accept E1 do
Text_IO.Put_Line ("E1 accepted");
end E1;
end TType;
function Func return TType is
begin
return X : TType;
end Func;
procedure Do_It (X : TType) is
begin
X.E1;
end Do_It;
begin
Do_It (Func);
end Test;
6. Why constructing functions is a mess [was Language lawyer question: task activation
7. Language lawyer question: access discriminants
8. language lawyer question, PURE subroutines again