12.07.2015 Views

PGI User's Guide

PGI User's Guide

PGI User's Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 12. Inter-language Callingexception to this convention is when a Fortran subroutine has alternate returns; call such a subroutine from C/C++ as a function returning int whose value is the value of the integer expression specified in the alternateRETURN statement.Upper and Lower Case Conventions, UnderscoresBy default on Linux, Win64, and OSX systems, all Fortran symbol names are converted to lower case. C and C++ are case sensitive, so upper-case function names stay upper-case. When you use inter-language calling, youcan either name your C/C++ functions with lower-case names, or invoke the Fortran compiler command withthe option –Mupcase, in which case it will not convert symbol names to lower-case.When programs are compiled using one of the <strong>PGI</strong> Fortran compilers on Linux, Win64, and OSX systems, anunderscore is appended to Fortran global names (names of functions, subroutines and common blocks). Thismechanism distinguishes Fortran name space from C/C++ name space. Use these naming conventions:• If you call a C/C++ function from Fortran, you should rename the C/C++ function by appending anunderscore or use C$PRAGMA C in the Fortran program. For more information on C$PRAGMA C, refer to“C$PRAGMA C,” on page 116.• If you call a Fortran function from C/C++, you should append an underscore to the Fortran function namein the calling program.Compatible Data TypesTable 12.1 shows compatible data types between Fortran and C/C++. Table 12.2, “Fortran and C/C++Representation of the COMPLEX Type,” on page 154 shows how the Fortran COMPLEX type may berepresented in C/C++.TipIf you can make your function/subroutine parameters as well as your return values match types, youshould be able to use inter-language calling.Table 12.1. Fortran and C/C++ Data Type CompatibilityFortran Type (lower case) C/C++ Type Size (bytes)character x char x 1character*n x char x[n] nreal x float x 4real*4 x float x 4real*8 x double x 8double precision double x 8integer x int x 4integer*1 x signed char x 1integer*2 x short x 2153

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!