Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Quick question about PRIVATE and PUBLIC
hi!

If I want to define some public, and some private variables in f90,
can I do the following:

PUBLIC

! Define several public variables
...

PRIVATE

!Define several private variables
...

Or is the public/private thing global? IOW, if I say PRIVATE, I have
to define each public variable as such individually?

Thanks
Neilen

--
you know its kind of tragic
we live in the new world
but we've lost the magic
-- Battery 9 (www.battery9.co.za)

Report this thread to moderator Post Follow-up to this message
Old Post
Neilen Marais
04-22-05 08:59 PM


Re: Quick question about PRIVATE and PUBLIC
Hi Neilen,

Neilen Marais wrote:

> hi!
>
> If I want to define some public, and some private variables in f90,
> can I do the following:
>
> PUBLIC
>
> ! Define several public variables
> ...
>
> PRIVATE
>
> !Define several private variables
> ...
>

No

> Or is the public/private thing global? IOW, if I say PRIVATE, I have
> to define each public variable as such individually?
>

Yes, this is the case. By default all variables at the top of the module
(don't know the technical term) are public. Sticking in a private statement
changes that for all such vars, unless they are explicitly declared public,

Hope this helps,

Ian



Report this thread to moderator Post Follow-up to this message
Old Post
Ian Bush
04-22-05 08:59 PM


Re: Quick question about PRIVATE and PUBLIC
Neilen Marais wrote:
> hi!
>
> If I want to define some public, and some private variables in f90,
> can I do the following:
>
> PUBLIC
>
> ! Define several public variables
> ...
>
> PRIVATE
>
> !Define several private variables
> ...
>
> Or is the public/private thing global? IOW, if I say PRIVATE, I have
> to define each public variable as such individually?

yes, if you say PRIVATE first, then you must name the PUBLIC variables
(and vice versa), eg.

module mod
private
public :: a, b, c
integer :: a, b, c, d, e, f
contains
function func
...
end function func
end module mod

so, when USEing this module:
USE mod
only variables a, b, c would be visible/useable (and d, e, f, and func
would be "hidden").

Report this thread to moderator Post Follow-up to this message
Old Post
Tom Micevski
04-22-05 08:59 PM


Re: Quick question about PRIVATE and PUBLIC
Hi

Thanks for the info Ian and Tom.

On Fri, 22 Apr 2005 13:28:22 +0000, Ian Bush wrote:


> Yes, this is the case. By default all variables at the top of the module
> (don't know the technical term) are public. Sticking in a private statemen
t
> changes that for all such vars, unless they are explicitly declared public
,
>
> Hope this helps,

It helps, but I was hoping I could save some typing one way or the other :)

Cheers
Neilen


--
you know its kind of tragic
we live in the new world
but we've lost the magic
-- Battery 9 (www.battery9.co.za)

Report this thread to moderator Post Follow-up to this message
Old Post
Neilen Marais
04-22-05 08:59 PM


Re: Quick question about PRIVATE and PUBLIC
"Neilen Marais" <junkmail@chatsubo.lagged.za.net> wrote in message
news:pan.2005.04.22.13.41.09.268766@chatsubo.lagged.za.net...
>
> It helps, but I was hoping I could save some typing one way or the other
:)
>
You can save some typing (and errors) by making objects public by adding
that attribute to their type specification:

module mod
private
integer, public  :: a, b, c, d, e, f

The statement form with a list is really only needed for operators.

Regards,

Mike Metcalf



Report this thread to moderator Post Follow-up to this message
Old Post
Michael Metcalf
04-22-05 08:59 PM


Re: Quick question about PRIVATE and PUBLIC
In article <pan.2005.04.22.12.15.22.49500@chatsubo.lagged.za.net>,
Neilen Marais <junkmail@chatsubo.lagged.za.net> wrote:

> Or is the public/private thing global? IOW, if I say PRIVATE, I have
> to define each public variable as such individually?

As others have answered, yes, I'm afraid you do.

I'll note as an aside that the notion you are looking for - that
something (in this case public or private, but it generalizes) might
apply only to entities declared in a certain range of statements -
doesn't "work" very well with Fortran declarations.

One might wish it were otherwise (I do), but it is hard to pin down
exactly what statement "declares" an entity. That's because the
declarations can be scattered among multiple statements. Some entities
can be declared implicitly just by using them. There is no single
statement you can point to and definitively say that is the statement
that declares an entity. While you might choose to think of it that way,
and you might write your code with such a style (as do I), that isn't
the way that the standard defines things.

So you can't easily talk about entities that are defined in a certain
range of statements. Of course, one could tie it down more precisely,
but then its is going to start to get complicated and arbitrary seeming.

At times I wish for a form of declaration that specified "this is
everything about this entity - there can't be any attributes declared
elsewhere", but we don't have that.

--
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

Report this thread to moderator Post Follow-up to this message
Old Post
Richard E Maine
04-22-05 08:59 PM


Re: Quick question about PRIVATE and PUBLIC
Richard E Maine wrote:

<snip>

> At times I wish for a form of declaration that specified "this is
> everything about this entity - there can't be any attributes declared
> elsewhere", but we don't have that.

With F, you come pretty close, since the
entity-oriented declarations are the only
ones allowed.

--
Walt Brainerd         +1-877-355-6640 (voice & fax)
The Fortran Company   +1-520-760-1397 (outside USA)
6025 N. Wilmot Road   walt@fortran.com
Tucson, AZ 85750 USA  http://www.fortran.com

Report this thread to moderator Post Follow-up to this message
Old Post
Walt Brainerd
04-22-05 09:00 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:26 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.