next up previous 252
Next: External Names
Up: Sun
Previous: General

Data Types

There is a simple correspondence between Sun FORTRAN and C numeric variable types. The standard types are given in the upper part of the table below, and non-standard extensions in the lower part. These should generally be avoided for reasons of portability, however, they are provided since HDS has corresponding data types.


Table: Corresponding data types for Sun Solaris
type Sun FORTRAN Sun C
INTEGER INTEGER int
REAL REAL float
DOUBLE DOUBLE PRECISION double
LOGICAL LOGICAL int
  CHARACTER*1 char
CHARACTER CHARACTER*n char[n]
BYTE BYTE signed char
WORD INTEGER*2 short int
UBYTE   unsigned char
UWORD   unsigned short int
POINTER INTEGER unsigned int

Although C defines unsigned data types of unsigned char (range 0 to 255), unsigned short (range 0 to 32767) and unsigned int (range 0 to 232-1), there are no corresponding unsigned data types in FORTRAN. There is also a C type called long int, however on Suns, this is the same as an int.

The C language does not specify whether variables of type char should be stored as signed or unsigned values. On Suns, they are stored as signed values in the range -128 to 127.

Similarly there is no C data type that corresponds to the FORTRAN data type of COMPLEX. However, since Sun FORTRAN passes all numeric variable by reference, a COMPLEX variable could be passed to a C subprogram where it might be handled as a structure consisting of two variables of type float.

A Sun FORTRAN LOGICAL value can be passed to a C int. Sun FORTRAN and C both use zero to represent a false value and anything else to represent a true value, so there is no problem with converting the data values.



next up previous 252
Next: External Names
Up: Sun
Previous: General

CNF and F77 Mixed Language Programming -- FORTRAN and C
Starlink User Note 209
P.M. Allan
A.J. Chipperfield
R.F. Warren-Smith
19 January 2000
E-mail:ussc@star.rl.ac.uk