[MPIWG Fortran] MPI-3 ticket 349: Fortran question
Jim Dinan
james.dinan at gmail.com
Tue Feb 4 13:24:21 CST 2014
Sorry it has taken me so long to respond to this --
Dave, thanks so much for the detailed example! I added this to the ticket
to make sure we don't lose it.
~Jim.
On Thu, Jan 2, 2014 at 11:36 AM, Dave Goodell (dgoodell) <dgoodell at cisco.com
> wrote:
> On Dec 24, 2013, at 11:36 AM, Jim Dinan <james.dinan at gmail.com> wrote:
>
> > Given that MPI_Aint will be at least the same size as ptrdiff_t, do we
> > actually have a problem with subtracting MPI_Aints to find pointer diffs?
> > It seems like this may actually be ok.
>
> There's still a problem. I don't think that ptrdiff_t has anything to do
> with it since that normally only comes into play when you subtract two
> _pointers_, not two integers acting sort of like pointers.
>
> As an example, take a look at this little test program. It subtracts two
> plausible addresses from the middle of the address space but underflows the
> signed arithmetic anyway. When I compile this with '-ftrapv' under clang
> then I get a core dump when executing this program.
>
> ----8<----
> #include <stdio.h>
> #include <limits.h>
>
> typedef long long MPI_Aint;
>
> int main(int argc, char **argv)
> {
> MPI_Aint a = LLONG_MIN; /* 0x8000000000000000LL */
> MPI_Aint b = 0x7ffffffffffffffcLL;
> MPI_Aint c = a - b; /* expect 0x4LL if signed overflow were defined */
> printf("a=%#llx b=%#llx c=%#llx\n", a, b, c);
> return 0;
> }
> ----8<----
>
> The overflow occurs because "(a - b)" is really "(-9223372036854775808 -
> 9223372036854775804)" in signed integer arithmetic. Note that most
> implementations will give you the expected value if you don't set
> '-ftrapv', but that's *undefined behavior* according to the C standard and
> should not be relied upon (see http://www.airs.com/blog/archives/120).
>
> This is all just the C side of things. I have no idea whether Fortran
> integer overflow is defined.
>
> -Dave
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpi-forum.org/pipermail/mpiwg-fortran/attachments/20140204/8ba2565f/attachment.html>
More information about the mpiwg-fortran
mailing list