When is a type declared to be PRIVATE 
Author Message
 When is a type declared to be PRIVATE

Section 4.4.2 of the fortran 95 standard states

     A data entity declared using a type with the SEQUENCE property is
not
     of the same type as an entity of a type declared to be PRIVATE or
     which has components that are PRIVATE.

Thus, the following program is clearly not standard conforming:

      MODULE M
        PRIVATE T, Y
        TYPE T
          SEQUENCE
          INTEGER I
        END TYPE
        TYPE(T) :: Y
        CONTAINS
          SUBROUTINE SUBR
            TYPE T
              SEQUENCE
              INTEGER I
            END TYPE
            TYPE(T) :: X
            X%I = 0
            Y = X
          END SUBROUTINE
      END

      PROGRAM MAIN
        USE M
        CALL SUBR
      END

It is less clear whether the following program is standard conforming:

      MODULE M1
        TYPE T
          SEQUENCE
          INTEGER I
        END TYPE
      END

      MODULE M2
        USE M1
        PRIVATE T, Y
        TYPE(T) :: Y
        CONTAINS
          SUBROUTINE SUBR
            TYPE T
              SEQUENCE
              INTEGER I
            END TYPE
            TYPE(T) :: X
            X%I = 0
            Y = X
          END SUBROUTINE
      END

      PROGRAM MAIN
        USE M2
        CALL SUBR
      END

The type T might appear to declared to be PRIVATE in the specification
part of module M2 , but Sun f95 does not consider it to be so.  Sun f95
considers a derived type to be declared to be PRIVATE only if its
original
definition is declared to be PRIVATE.  I would be interested in knowing
if
any compilers give an error when compiling the second program.

Bob Corbett



Wed, 23 Jul 2008 18:01:59 GMT  
 When is a type declared to be PRIVATE

Quote:
> I would be interested in knowing
> if
> any compilers give an error when compiling the second program.

Seems to compile without errors using g95..

Cheers,

Joost



Wed, 23 Jul 2008 18:13:06 GMT  
 When is a type declared to be PRIVATE
  [much elided]

I'm afraid I didn't carefully read through the above. It isn't
unreasonably long, but I'm not feeling like taking much more time going
into careful analysis right now on a Saturday morning.

Quote:
> Sun f95 considers a derived type to be declared to be PRIVATE only if its
> original definition is declared to be PRIVATE.

But I'll comment on that because it is a *VERY* familliar issue. I
recall it more in regard to a different application, unrelated to the
type equivalence of sequence types. There used to be restrictions
against doing several things with private types (such as having public
procedures with dummy arguments of private type). Those restrictions
were, IMO (and the rest of J3 finally got convinced also), wrongheaded
anyway and they got pulled from later versions of the standard. But
there was a long debate about their interpretation in f90.

One proposed interpretation made private types all but unusable in my
opinion; it also had "strange" side effects and raised secondary
interpretaion issues. You might guess from the way I describe it that I
argued against that interpretation. That turned out to be the way that
the large majority of compilers were implementing it, but it just didn't
"work". It took a fair amount of detective work to find that the
standard actually supported the interpretation I wanted - the words are
a bit hidden. But the words were found, and the interpretation that I
argued for did pass. Compilers even changed to correspond to the
published interp, but I recall observing the long lag times that it took
to make it into actual released compilers.

The gist of that interpretation was exactly the point that you cite
above - something is private only if it is declared private in the
module of its original definition.

I sort of wish that the terms private/public were not used for this
stuff because they aren't quite right and thus lead to this question.
Part of the owording subtlety is that, if you read *VERY* carefully,
you'll find that the standard doesn't say that the PRIVATE attribute
makes something private. Igt does say that the PUBLIC attribute makes
something public, but not the other way around. I remember the words
almost exactly even without looking them up. From memory (but I'msure
darned close),

  "the PRIVATE attribute declares that the entity is not a public entity
of the module."

why the compilicated negative form? Why not just say that it is private
instead of not public? Because they aren't the same thing. In this
regard, note also the "of this module". If something is public in the
module of its original declaration, then it can never be private. Some
other module might decline to make it public from that second module,
but it is still "available" from the first, so it is stil public.

One might say that, in modules other than the one of the original
definition, a PRIVATE attribute can't go back and change anything about
the original,including the fact that the original is public. Other
modules can decline to "export" (a term not used by the standard, but
one that I think helps) it themselves, but that doesn't change the
original.

The f90 interp numbers 91 and 161 stick in my mind (I told you it was a
long debate, to imprint the interp numbers on my mind for over a
decade). As I said, they weren't about sequence types, but I bet they
answer your question anyway.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain



Thu, 24 Jul 2008 01:51:44 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. I am not deaf, but am I mute?

2. Private and Limited Private types

3. Ambiguity in Ada LRM about private types and type conversions

4. Type conversions involving private types

5. Derived types containing components of PRIVATE type

6. I am new to LabVIEW and I am having the classic problem of...

7. I am using LABview 5.0 and I am having difficulty with...

8. I am using a timed while loop and am unable to get the loop...

9. I am using HP 4263ALCR meter, and I am trying to use the...

10. I am working in LabVIEW 6i and I am wanting to build a exe in Apllication Builder

11. I am inputting my guitar tunes(.wav files) and I am trying...

12. I am not ale to compile my DLL when I am linking to...

 

 
Powered by phpBB® Forum Software