Code Comments
Programming Forum and web based access to our favorite programming groups.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)
Post Follow-up to this messageHi 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
Post Follow-up to this messageNeilen 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").
Post Follow-up to this messageHi 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)
Post Follow-up to this message"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
Post Follow-up to this messageIn 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
Post Follow-up to this messageRichard 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.