Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

malloc declaration?

chauvjo
Novice
447 Views
Should you declare theelemental intrinsic function malloc in a program? Is the declaration in this example appropriate for the 64 bit compiler? I am using a program that declares malloc as an integer that is compiled 64 bit and is working fine. Is the declaration correct, ignored, or have I just been lucky? I believe p1 and p1 are correct just not sure how to handle the declaration (if it is needed or required) of malloc.

[cpp]      program mem
      implicit none
      integer malloc,i       <==== malloc declaration
      
      pointer (p1, fred)
      pointer (p2, jack)
      integer size
      real fred(*),jack(*)

      print *,'How big?'
      read *,size

      p1 = malloc(4*size)
      p2 = malloc(4*size)

      do i=1,(size)
              fred(i)=i
              jack(i)=i
      end do
      print *,jack(size),fred(size)
      end
[/cpp]

0 Kudos
1 Reply
Steven_L_Intel1
Employee
447 Views

You should not declare malloc, but if you want to, do it this way:

integer(int_ptr_kind()) malloc

Your declaration is ignored if it is an intrinsic.

This will be correct on both 32 and 64-bit systems.
0 Kudos
Reply