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

How to express the following codes of C in Fortran

Zhanghong_T_
Novice
338 Views
Hi all,
I am trouble in expressing C in Fortran:
in C, the pointer is very flexible. Can I also realize the same function in Fortran for the following codes:
int **pointer;
int *pointer[10];
in addition, how to express the following codes with Fortran:
enum datatype {int, float, double};
#define delete(current)
current=NULL;
Thanks,
Zhanghong, Tang
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
338 Views

int *pointer[10];

You can introduce an array of derived types as a medium:

TYPE T_Ptr
INTEGER, POINTER:: p
END TYPE T_Ptr
TYPE(T_Ptr):: Ptr(10)

int **pointer;

This really depends on context. You can use the trick above:
TYPE(T_Ptr), POINTER:: pPtr
If int** declaration is for a dummy argument, this can be achieved by declaring the argument POINTER, e.g.
void AllocAnInt(int** pointer) {
*pointer = new int;
**pointer = 0
}
SUBROUTINEAllocAnInt(ptr)
INTEGER, POINTER:: ptr
ALLOCATE(ptr)
ptr = 0
END SUBROUTINE
enum datatype {int, float, double};
I've never seen that. Gosh it's allowed?
#define delete(current)
current=NULL;
This is just a simple macro substitution. IMO there's no need for this, as current = 0 (NULL) is simple enough. Standard Fortran can emulate C macros in form of:
- Statement functions, which are obsolete but can get useful at times; they're less powerful than C macros. For example:
!Declaration section
INTEGER RGB, iR, iG, iB
RGB(iR,iG,iB) = ISHL(iB,16) + ISHL(iG,8) + iR
!Executable section
iRGB = RGB(255, 0, 255) !Gives #00FF00FF = Pink
- Internal procedures (the ones that go beyond CONTAINS statement within a parent procedure body)
In addition, CVF supports FPP (which is"Fortran-aware" version of C preprocessor), which has /m switch to allow expansions of macros in form of #define. I don't particularly like it, but you can take a look at the docs.
Jugoslav

Message Edited by JugoslavDujic on 04-09-2004 02:09 PM

Message Edited by JugoslavDujic on 04-09-2004 02:12 PM

0 Kudos
Reply