From: robert.corbett on
On Mar 25, 8:59 am, nos...(a)see.signature (Richard Maine) wrote:
> pehache-tolai <pehach...(a)gmail.com> wrote:

> There is currently no portable standard-conforming way.
>
> Bob mentioned the LOC function, but I think he overstates when he says
> it is "almost always present." I haven't actually checked recently, but
> I doubt it is present in some of the compilers I have most used. I'd
> probably agree if the claim were modified to say that almost all
> compilers have some similar functionality, possibly under a different
> name.

I would be very interested in knowing if there is a Fortran
implementation that does not provide the function LOC. LOC
is so commonly used, I would think an implementation that
did not provide it would not be viable.

Bob Corbett
From: Richard Maine on
Phred Phungus <Phred(a)example.invalid> wrote:

> write(*,'(a,i0)') 'In f08: ', C_SIZEOF(sp)
> 1
> Error: Function 'c_sizeof' at (1) has no IMPLICIT type
....
> I don't see an obvious culprit for the error.

I would say that the most obvious culprit is that, as per the comment,
C_SIZEOF is an f2008 feature. Since GFortran doesn't (yet?) claim to be
even a full f2003 compiler, much less f2008, you can't necessarily count
on f2008 features.

Given that James appears to have gotten it to work with GFortran, I
posit that perhaps this function might have been fairly recently added
and that he has a newer version of GFortran than you do. While I don't
know that to be so, it seems like a good guess.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: robert.corbett on
On Mar 25, 2:58 am, robert.corb...(a)sun.com wrote:
> On Mar 25, 12:49 am, pehache-tolai <pehach...(a)gmail.com> wrote:
>
> > Hello,
>
> > In my code I need to determine the size of various variables which are
> > defined as derived types.
>
> > Until now I used to use the INQUIRE() function, but it doesn't work if
> > the derived type contains some pointers. Is there a (not too
> > complicated) solution ? I don't need to know the size of the objects
> > pointed or allocated by the pointers, but only the size of the derived
> > type.
>
> > Thanks,
>
> > --
> > pehache
>
> The easiest way would be to declare an array of two of them
> and subtract the LOC of the second from the LOC of the first.
> For example, using Oracle Solaris Fortran in 32-bit mode, the
> program
>
> PROGRAM MAIN
> TYPE T
> TYPE(T), POINTER :: P
> END TYPE
> TYPE(T) A(2)
> PRINT *, LOC(A(2)) - LOC(A(1))
> END
>
> prints
>
> 4
>
> The function LOC is a nonstandard extension, but one that
> is almost always present. I showed in a previous posting
> how to do the same thing using only standard features,
> but some people thought that approach was too ugly to even
> consider.
>
> Bob Corbett


There are a couple of points that are unlikely to cause
problems, but which are, theoretically, possible problems.
The first is that the Fortran standards do not require an
implementation to use the same layout for textually
identical type definitions. The second is that an
implementation might add some padding between elements of
arrays to make address arithmetic easier. The
implementation need not provide the padding for scalar
variables and components. In practice, every implementation
of which I am aware always uses the same padding whether a
variable is a scalar or an array.

Bob Corbett
From: Richard Maine on
<robert.corbett(a)sun.com> wrote:

> On Mar 25, 8:59 am, nos...(a)see.signature (Richard Maine) wrote:
> > pehache-tolai <pehach...(a)gmail.com> wrote:
>
> > There is currently no portable standard-conforming way.
> >
> > Bob mentioned the LOC function, but I think he overstates when he says
> > it is "almost always present." I haven't actually checked recently, but
> > I doubt it is present in some of the compilers I have most used. I'd
> > probably agree if the claim were modified to say that almost all
> > compilers have some similar functionality, possibly under a different
> > name.
>
> I would be very interested in knowing if there is a Fortran
> implementation that does not provide the function LOC. LOC
> is so commonly used, I would think an implementation that
> did not provide it would not be viable.

Well, I don't maintain a list because it isn't a feature I use. I don't
use the feature because I've run into compilers that don't support it.
The F90 compiler vendor that provided the very first f90 compiler comes
to mind. That is also the vendor whose f90/f95 compilers I most often
used, so it counts as a *MAJOR* case for me - not just some obscure nit.
It wouldn't surprise me at all to find that there are others as well.
That one case was enough to keep me from using it, so, as noted, I
didn't even check others to make a list.

program bob
integer :: i
write (*,*) loc(i)
end

nagfor clf.f90
NAG Fortran Compiler Release 5.2(711)
[NAG Fortran Compiler normal termination]
Undefined symbols:
"_loc_", referenced from:
_main in clf.o

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: robert.corbett on
On Mar 25, 7:26 pm, nos...(a)see.signature (Richard Maine) wrote:
> <robert.corb...(a)sun.com> wrote:
> > On Mar 25, 8:59 am, nos...(a)see.signature (Richard Maine) wrote:
> > > pehache-tolai <pehach...(a)gmail.com> wrote:
>
> > > There is currently no portable standard-conforming way.
>
> > > Bob mentioned the LOC function, but I think he overstates when he says
> > > it is "almost always present." I haven't actually checked recently, but
> > > I doubt it is present in some of the compilers I have most used. I'd
> > > probably agree if the claim were modified to say that almost all
> > > compilers have some similar functionality, possibly under a different
> > > name.
>
> > I would be very interested in knowing if there is a Fortran
> > implementation that does not provide the function LOC. LOC
> > is so commonly used, I would think an implementation that
> > did not provide it would not be viable.
>
> Well, I don't maintain a list because it isn't a feature I use. I don't
> use the feature because I've run into compilers that don't support it.
> The F90 compiler vendor that provided the very first f90 compiler comes
> to mind. That is also the vendor whose f90/f95 compilers I most often
> used, so it counts as a *MAJOR* case for me - not just some obscure nit.
> It wouldn't surprise me at all to find that there are others as well.
> That one case was enough to keep me from using it, so, as noted, I
> didn't even check others to make a list.
>
> program bob
> integer :: i
> write (*,*) loc(i)
> end
>
> nagfor clf.f90
> NAG Fortran Compiler Release 5.2(711)
> [NAG Fortran Compiler normal termination]
> Undefined symbols:
> "_loc_", referenced from:
> _main in clf.o
>
> --
> Richard Maine | Good judgment comes from experience;
> email: last name at domain . net | experience comes from bad judgment.
> domain: summertriangle | -- Mark Twain

I can believe the NAGWare compiler would not support LOC.
Sun stopped purchasing a license for the NAG compiler
during the lean times, so it has been a while since I used
it. I do wonder if there is a second compiler that does not
support LOC.

Bob Corbett