Frequently Asked Questions - Fortran 90 Xlib Interface Fortran 90 Xlib Interface FAQ - created 12/20/95. - last updated 04/09/99. This Fortran90 interface was created by Garnatz and Grovender, Inc. email: gginc@gginc.biz URL: http://gginc.biz Please send additions or corrections to the above email address. Necessary pieces: xlib.f90 xlibf90.c Optional pieces: ast.f90 xlib-faq.txt(this file) A new feature, 10/11/96: A limited version of the interface revised for the "F" language from Imagine1 Inc. files: ast.F xlib.F (xlibf90.c and xlib-faq.txt are the same) A long pointer enhancement, for the DEC Alpha architecture, 11/11/96: compile with -DLONG_PTR Asteroids program: ! Keyboard Controls ! ! e - turn left ! r - turn right ! d - set autorotate left ! f - set autorotate right ! ; - accelerate ! ' - fire bullet ! spacebar - hyperspace jump ! p - pause ! s - New Ship ! q - Quit Q1) > How do you handle C pointers in Fortran 90. I treat them as default integers. I cast them to (int) passing back from C, and use an indirect index to the pointer when calling C. See more information below. (Q7) Q2) > How about C Structures to and from f90 derived data types There is no guarantee in Fortran 90 that derived data types will match up with C structs; so to pass them safely I copy all components to individual variable, pass them as arguments, and then copy them back to structure/type components. Q3) > How about C strings to and from f90 characters Similar to structures above, the only safe and portable way I know of, is to copy to an array of integers, then back again. Q4) > I tried to compile xlibf90.c using gcc version 2.6.3 on Linux but I got > a huge amount of errors: > > gcc -c xlibf90.c > xlibf90.c:77: parse error before `*' > xlibf90.c:80: `idisp' undeclared here (not in a function) > xlibf90.c:80: warning: data definition has no type or storage class > xlibf90.c:81: parse error before `return' > xlibf90.c:98: parse error before `*' > > > Do these messages make sense to you??? > (I'm not familiar with C) > > Best Regards, > > Jens B. Helmers > jenhel@marin.unit.no Short answer: try cc -DSPARC -c xlibf90.c Long answer: when Fortran compilers set up entry points for external calls there are 3 popular styles: ' call fred' becomes a call to 1) fred_ trailing underscore, popular on Sun SPARC and other UNIX systems 2) FRED all upper case, used by Cray Research PVP systems 3) _fred leading underscore, used by others - I don't know any specifically (implemented 10/11/96.) In order to write C routines that are callable by Fortran 90 on any system I have to handle thses possible function names in the C code, so I have put in a lot of conditional compilation tests (#ifdef) to try and test for the kind of system you are using, and compile the right version of the source code. If your specific system is not in the test sequence, then you need to specify an option on the command line with -D. Note: I fixed it to make trailing underscore default. Q5) > When will all the call interfaces be complete? I don't know, this is a part time "fun" project. Without funding it could take years. (and may never be complete) Q6) > When can you do Xt and Motif (Xm) call interfaces? See Q5, and don't hold your breath. Are you willing to send money? Q7) > I am trying to compile on a DEC AXP system, and I get errors: xlibf90.c: In function `defaultgc_': xlibf90.c:204: warning: cast from pointer to integer of different size xlibf90.c: In function `defaultgcofscreen_': xlibf90.c:219: warning: cast from pointer to integer of different size xlibf90.c: In function `defaultscreenofdisplay_': xlibf90.c:264: warning: cast from pointer to integer of different size xlibf90.c: In function `defaultvisual_': (SNIP) The DEC alpha chip uses 40 bit addresses, too long to fit into a default integer either in f90 or C. I wiil need to convert to long int in the C code, and selected_int_kind( ? ) of something that will hold the whole address (pointer). This behavior may occur on other systems as well. In general the following inequality must be satisfied: Size_of_Fortran_integer >= Size_of_C_integer >= Size_of_C_pointer By using a long C integer to hold the pointer, and a long f90 varaible this wil work correctly. Implemented and tested for the DEC Alpha machines. 11/11/96. Size_of_Fortran_integer(kind=8) >= Size_of_C_long >= Size_of_C_pointer DEC Alpha: 64 = 64 > 40 To determine the sizes of the various integer types run the following C and Fortran 90 programs. ========== sizes.c ============= #include main() { short sval; int ival; long lval; /* does your compiler accept long long? */ int *p; ival = sizeof(sval); printf(" size of a short is %d \n",ival); ival = sizeof(ival); printf(" size of an int is %d \n",ival); ival = sizeof(lval); printf(" size of a long is %d \n",ival); ival = sizeof(p); printf(" size of a ptr is %d \n",ival); } ========== end of sizes.c ============= ========== sizes.f90 ============ program sizes ! integer :: itype, jtype, i ! jtype = 0 do i=1,30 itype = selected_int_kind(i) if(itype .ne. jtype) then write(unit=*,fmt=*) " new kind ", itype, " at ",i jtype = itype endif if (itype <= 0) then exit endif enddo ! itype = kind(jtype) write(unit=*,fmt=*) " default kind ", itype inquire (iolength=jtype) itype itype = bit_size(jtype) write(unit=*,fmt=*) " size (for I/O) of default integer ", & jtype," = ",itype," bits " stop end program sizes ========== end of sizes.f90 ============