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

how can i use pointer like C pointer?

qiu_n_
Beginner
380 Views
i have a think ,i hope use pointer like C ,following is c code: ......... char * data; int *iptr; float* fptr; double * dbptr; data = new char[100*4]; iptr = (int *)&data[0]; fptr = (float *)&data[0]; dbptr = (double *)&data[0]; i not't kown how can code this use fortran pointer? please tell me answer, thanks.
0 Kudos
2 Replies
Johannes_Rieke
New Contributor III
380 Views

Hi Qiu.

you might find integer pointers helpful (sometimes called Cray pointers), which are non-standard Fortran but supported also by Intel compilers and gfortran:

https://software.intel.com/en-us/node/679644

https://gcc.gnu.org/onlinedocs/gfortran/Cray-pointers.html

I don't know in which context you like to use it, but maybe the associate construct is what you like to have?

https://software.intel.com/en-us/node/679014

Best regards, Johannes

0 Kudos
Ronald_G_2
Beginner
380 Views

Fortran tries to prevent you from aliasing the same data as integer, real, and double.  That's really really bad programming practice, hopefully you know this.  In Fortran you can also look at the TRANSFER intrinsic if you really want to treat the data as different intrinsic data types for different purposes.

0 Kudos
Reply