HP Fortran Programmer's Guide (March 2010)
Calling C routines from HP Fortran
Case sensitivity
Chapter 8 197
Case sensitivity
Unlike HP Fortran, C is a case-sensitive language. HP Fortran converts all external names to
lowercase, and it disregards the case of internal names. Thus, for example, the names foo
and FOO are the same in Fortran. C, however, is a case-sensitive language: foo and FOO are
different in C. If an HP Fortran program is linked to a C object file and references a C
function that uses uppercase characters in its name, the linker will not be able to resolve the
reference.
If case sensitivity is an issue when calling a C function from an HP Fortran program, you
have two choices:
• Compile the Fortran program with the +uppercase option, which forces Fortran to use
uppercase for external names.
•Use the $HP$ ALIAS directive to specify the case that Fortran should use when calling an
external name.
It is unusual that all names in the C source file would be uppercase, which would be the only
case justifying the use of the +uppercase option. Therefore, we recommend using the
$HP$ ALIAS directive. This directive enables you to associate an external name with an
external name, even if the external name uses uppercase characters.
The $HP$ ALIAS directive also has the advantage that you can use it with the %REF and %VAL
built-in functions to specify how the arguments are to be passed without having to repeat
them at every call site.
Consider the following C source file, which contains a function to sort an array of integers:
Example 8-3 sort_em.c
#include <stdio.h>
void BubbleSort(int a[], int size)
{
int i, j, temp;
for (i = 0; i < size - 1; i++)
for (j = i + 1; j < size; j++)
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}