Private module procedures 
Author Message
 Private module procedures

How do I make a procedure private to a module?

    module testing
    ! want to expose function "good" but not function "secret".
    ! integer, PRIVATE:: secret    ! doesn't work
    contains
        integer function good(i)
        integer i
        good= i
        return
        end function good

        !integer, PRIVATE:: function secret(i)  ! doesn't work
        integer function secret(i)
        integer i
        ! PRIVATE secret   ! doesn't work either
        bad= -i
        return
        end
    end module testing

I could have sworn the first construct was legal.  The Portland pgf90
(not sure what release) accepts it but Compaq Visual fortran 6.6
doesn't.  Both compilers reject the other two attempts.  Is CVF
correct?

I could always move secret() to a module "testing_priv" which is used
only within "testing", but is there a better way?

--
pa at panix dot com



Mon, 17 Jul 2006 02:10:12 GMT  
 Private module procedures

Quote:
> I could have sworn the first construct was legal.  The Portland pgf90
> (not sure what release) accepts it but Compaq Visual Fortran 6.6
> doesn't.  Both compilers reject the other two attempts.  Is CVF
> correct?

It's legal, but secret will not be interpreted as the name of a
module procedure.  You need to say:

private secret

to make the module procedure secret private.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end



Mon, 17 Jul 2006 02:57:52 GMT  
 Private module procedures

Quote:

> How do I make a procedure private to a module?

I do it opposite to what you want to do. I make everything PRIVATE by default and then
explicitly set the module members I want PUBLIC:

Quote:

>     module testing
>     ! want to expose function "good" but not function "secret".

      ! Make everyting PRIVATE by default
      PRIVATE

      ! Make only the members I want PUBLIC, public.
      PUBLIC :: good

Quote:
>     contains
>         integer function good(i)
>         integer i
>         good= i
>         return
>         end function good

>         integer function secret(i)
>         integer i
>         bad= -i
>         return
>         end
>     end module testing

Dunno which way is "better"...but the method above fits in with my perception anchor. :o)

cheers,

paulv

--
Paul van Delst



Mon, 17 Jul 2006 03:05:29 GMT  
 Private module procedures

Quote:

> How do I make a procedure private to a module?

  private :: secret

or make the default private with just plain

  private

(in which case, you'll need to declare those things public that
need to be).

Quote:
>     ! integer, PRIVATE:: secret    ! doesn't work

That's because of the integer part.  You can't redeclare
things about the procedure here.  The interface of secret is
already known.  You aren't allowed to redeclare it (much less
an incomplete part of it; the return type is part of the interface).

Quote:
>    !integer, PRIVATE:: function secret(i)  ! doesn't work

That's because the only place you can ever have PRIVATE is in
the part of a module before the contains.

Quote:
> I could have sworn the first construct was legal.

It is, but it doesn't mean what you think.  That would be
declaring something *ELSE* to be a private integer.  Either
a variable or an external procedure (can't tell without more
context).  You never declare the type (or anything else about
the interface) of a module procedure anywhere except in the
procedure itself.

--
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain



Mon, 17 Jul 2006 03:49:23 GMT  
 Private module procedures


Quote:
>> I could have sworn the first construct was legal.  The Portland pgf90
>> (not sure what release) accepts it but Compaq Visual Fortran 6.6
>> doesn't.  Both compilers reject the other two attempts.  Is CVF
>> correct?

>It's legal, but secret will not be interpreted as the name of a
>module procedure.  

I don't think it's legal - the integer attribute, as you say, makes this
declaration of SECRET different from the module procedure.  That means there
are two different SECRETs in the same scope, which is illegal.

As you say, simply using:

  private secret

at the module level is the correct solution.

Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH

User communities for Intel Software Development Products
  http://softwareforums.intel.com/
Intel Fortran Support
  http://developer.intel.com/software/products/support/



Mon, 17 Jul 2006 04:53:19 GMT  
 Private module procedures

Quote:
> I do it opposite to what you want to do. I make everything PRIVATE
> by default and then explicitly set the module members I want PUBLIC:

Good idea.

Thanks also to James Van Buskirk for the solution to my problem, which
was to use a private *statement* instead of a private *attribute*
in a (conflicting) declaration statement.

--
pa at panix dot com



Mon, 17 Jul 2006 03:38:37 GMT  
 Private module procedures

Quote:

>Thanks also to James Van Buskirk for the solution to my problem, which
>was to use a private *statement* instead of a private *attribute*
>in a (conflicting) declaration statement.

It wasn't the statement vs. attribute, but your also giving a type to the
routine at the module level.  That was what got you in trouble. Module
procedures define their own interfaces.

Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH

User communities for Intel Software Development Products
  http://softwareforums.intel.com/
Intel Fortran Support
  http://developer.intel.com/software/products/support/



Tue, 18 Jul 2006 00:11:17 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Calling Private Module Procedures Externally ...

2. Passing module procedures to external procedures -- type issues

3. array-valued procedure: I/O reccursion with module procedure

4. import selected module variables within that module's procedures

5. Modules, private wordlists, etc

6. cant see PRIVATE variable in MODULE SUBROUTINE when debugging with IFC/IDB v7.1

7. Module USE question re: PUBLIC/PRIVATE

8. Private use of a module?

9. Accessing Private Module Data using pointers?

10. F90: importing public type into (mostly) PRIVATE module.

11. How private are private methods?

12. Non private & private Import

 

 
Powered by phpBB® Forum Software