Re: Pointers to derived type objects in COMMON



On Apr 27, 3:48 pm, Walter Spector <w6ws_xthiso...@xxxxxxxxxxxxx>
wrote:
   type wws_t ! No SEQUENCE and has default initialization
     integer :: x = 1, y = 2, z = 3
   end type
   type (wws_t), pointer :: my_wwsptr
   common /block/ my_wwsptr


As follow up question: What if there is a SEQUENCE attribute? Is this
then valid or not? (The default initializer does not get applied to
the pointer, only to its target. Thus there is no reason why it should
be invalid --- unless C589 does not allow it.)



"C589 (R558) If a common-block-object is of a derived type, it shall be
a sequence type or a type with the BIND attribute and it shall have no
default inititialization."

But what about *pointers* to the objects?  If I merely want to place
a pointer to the object in the COMMON block, my reading of §5.5.2
says that it is legal to allow the pointer regardless.

Contrary to you, my reading is that this applies also to a pointer to
a derived type.


However, even if it does not apply (then see my question above), one
can argue that without SEQUENCE it is invalid:

a) "A data pointer shall be storage associated only with data pointers
of the same type and rank." (§5.5.2.3)

b) "Data entities in different scoping units also have the same type
if they are declared with reference to different derived-type
definitions that specify the same type name, all have the SEQUENCE
property or all have the BIND attribute, have no components with
PRIVATE accessibility, and have type parameters and components that
agree in order, name, and attributes." (§4.5.1.3)

c) "A pointer occupies a single unspecified storage unit that is
different from that of any nonpointer object and is different for each
combination of type, type parameters, and rank." (§16.4.3.1, (8))

d) "Named common blocks of the same name shall be of the same size in
all scoping units of a program in which they appear" (§5.5.2.4)

Glue this all together and you see the SEQUENCE is needed. (Unless the
same TYPE is host/use associated in all scoping units where that
COMMON block appears; then we are back at asking whether C589
applies.)

Tobias
.



Relevant Pages

  • Re: Rvalue of struct type
    ... the expression "funTest.a" yields an rvalue of type array of char, ... how can it be converted to pointer type when we can have pointer ... the next sequence point, or modifying it, results in undefined ...
    (comp.lang.c)
  • Re: Unlimited polymorphic pointers
    ... Doesn't the SEQUENCE attribute require that the data items in the binary structure be in the same order, at least up to the point where they deviate? ... You do things like use a variable-sized array (needs to be a pointer to ... trick of making a derived type with a single pointer component. ... I use a much safer approach that only transfers among derived types holding a single derived-type pointer, and I only allocate or deallocate in the context of the actual data type. ...
    (comp.lang.fortran)
  • Re: AfxBeginThread startup times and overhead
    ... If you want to pass in the sequence number, you can pass it in as ... The fact that the pointer value you dereference is complete ... One thing you can be certain of when you use Sleep() like this: ... >calling function sets and the thread clears, ...
    (microsoft.public.vc.mfc)
  • Re: doubt in USING POINTERS
    ... sequence point ... > undefined behaviour for some reason, it doesn't mean that the object's ... > valid pointer any more. ... > duration suitable for those temporary objects returned by a function. ...
    (comp.lang.c)