Showing results for 
Search instead for 
Did you mean: 
Valued Contributor III
1 View

Unexpected "has stopped working" message: issue with C_F_POINTER procedure in ISO_C_BINDING

The following simple code works fine with gfortran but fails with an unexpected "has stopped working" message with Intel compiler (version 16, update 1).  It feels like one of those simple code constructs that has worked umpteen times previously with Intel compiler but something has changed which causes it to fail now.  But I just can't figure out the problem.

module m

   use, intrinsic :: iso_c_binding, only : c_char, c_int, c_ptr, c_f_pointer
   use, intrinsic :: iso_fortran_env, only : output_unit

   implicit none


   subroutine Fsub( Str, LenStr ) bind(C, name="Fsub")

      !.. Argument list
      type(c_ptr), intent(in), value    :: Str
      integer(c_int), intent(in), value :: LenStr

      blk: block
         character(kind=c_char,len=LenStr), pointer :: f_str => null()
         call c_f_pointer( Str, f_str )
         write(output_unit,*) "In Fsub: Str is ", f_str
         f_str => null()
      end block blk


   end subroutine Fsub

end module m
#include <string.h>

void Fsub(const char *, int);

int main()
   const char * s = "Hello World!";
   int len_s;

   len_s = strlen(s);

   Fsub(s, len_s);

C:\temp>ifort /c /standard-semantics /warn:all f.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R
) 64, Version Build 20151021
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

C:\temp>cl /c c.c
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.40629 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.


C:\temp>link c.obj f.obj /out:p.exe
Microsoft (R) Incremental Linker Version 12.00.40629.0
Copyright (C) Microsoft Corporation.  All rights reserved.



0 Kudos
3 Replies
1 View

It isn't the C_F_POINTER, the

It isn't the C_F_POINTER, the error is happening as soon as the BLOCK is entered. We'll take a closer look.

Retired 12/31/2016
0 Kudos
1 View

Escalated as issue

Escalated as issue DPD200381625.For some reason the compiler is trying to copy the string just setting up the pointer, but using a NULL address to do it.

Retired 12/31/2016
0 Kudos
Valued Contributor III
1 View

Thanks Steve for your follow

Thanks Steve for your follow-up.  Yes, BLOCK seems to be the problem - it works without it.

0 Kudos