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

Qs about Pointer use

gelarimer
Beginner
438 Views

INTEGER(1) , ALLOCATABLE, TARGET:: Buf(:)

TYPE(T_PRINTER_INFO_2) PI2
POINTER(pPI2, PI2)
....
....
ALLOCATE(Buf(iBytesNeeded), STAT = iErr)

! Buf() will be filled inwith PRINTER_INFO_2 structure
! by win32 fn. GetPrinter()

pPI2 = LOC(Buf)
....
DEALLOCATE(Buf, STAT = iErr)
.....

Questions

1) Pointersand Targets should be the same type, but Buf is type Integer and pPI2points to a Derived Data type, is this a potential problem in theabove code?

2) does Buf() need the Target attribute?

3)would INTEGER(4) for Buf()be better for the Compiler?
(Can always calculatethe correct number of dbl words to Allocate)

4) OR would it be more appropriate, here,to use the intrinsic function MALLOC() to achieve the same results?

Thanks for any information.

0 Kudos
2 Replies
Steven_L_Intel1
Employee
438 Views
You should use malloc for this - ALLOCATABLE allows the compiler to make some assuimptions that your program might violate. Typically, PI2 would be declared as type T_PRINTER_INFO, or whatever... Try not to "fool" the compiler if you don't have to.
0 Kudos
gelarimer
Beginner
438 Views
Thanks Steve, appreciate the information.
0 Kudos
Reply