This is the mail archive of the mailing list for the GNU Fortran project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR 36322/36463

On Thu, Oct 23, 2008 at 11:05:41PM +0200, Dominique Dhumieres wrote:
> You have been faster than me to reduce the problem!
> There is a last one with the following reduced test:
> module other_fun
>    use ISO_C_BINDING
>    implicit none
>    private
> end module other_fun
> program fptr
> !   use ISO_C_BINDING
>    use other_fun
>    implicit none
>    type(C_FUNPTR) fp
> end program fptr
> which gives
> pr35971_red_1.f90:11.17:
>    type(C_FUNPTR) fp
>                 1
> Error: Derived type 'c_funptr' at (1) is being used before it is defined
> If I comment 'private' of if I uncomment the 'use ISO_C_BINDING' in
> the program, the error disappears. I have no idea if this the way it
> is supposed to work: does 'private' prevent 'ISO_C_BINDING' to be
> associated in the program?

I could be reading the F95 standard incorrectly, so you'll need
to decide for yourself.  The answer is 'yes' and gfortran is
giving a correct error message.

  11.3.2 The USE statement and use association

    The local name of an entity made accessible by a USE statement may
    appear in no other specification statement that would cause any
    attribute (5.1.2) of the entity to be respecified in the scoping unit
    that contains the USE statement, except that it may appear in a PUBLIC
    or PRIVATE statement in the scoping unit of a module.

    The appearance of such a local name in a PUBLIC statement in a module
    causes the entity accessible by the USE statement to be a public entity
    of that module.  If the name appears in a PRIVATE statement in a module,
    the entity is not a public entity of that module.  If the local name
    does not appear in either a PUBLIC or PRIVATE statement, it assumes
    the default accessibility attribute (5.2.3) of that scoping unit.

The blank PRIVATE in your code changes the default accessibility
to PRIVATE, so all of the PUBLIC entities in ISO_C_BINDING are
private to other_fun unless you explicitly declare the entities
to be PUBLIC.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]