Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Support and use of the `fortran` keyword in C

Tags:

c

keyword

Defined in the C standard is an optionally-supported keyword fortran

C99 language standard, section J.5.9:

The fortran function specifier may be used in a function declaration to indicate that calls suitable for FORTRAN should be generated, or that a different representation for the external name is to be generated.

This section remains unchanged in the C11 standard.

Nowhere else in either standard says anything else about this keyword. This section references section 6.7.4, Function Specifiers, which is what it seems to be, but the only one is inline, and the language involved tailors to that, and how one might use fortran isn't apparent.

The keyword is contained in the "Common Extensions" section (!), so universal support is not expected, and indeed, it is not present: my copy of GCC 7.2.0 doesn't recognize it.

Since I can't seem to use it,
a) How would one use the fortran keyword in C code?
b) What compilers support/supported this keyword?

like image 233
Orion Avatar asked Sep 25 '19 00:09

Orion


1 Answers

The BC4.5 compiler for DOS/Win16 supports said keyword. It changes the calling convention of the function to FORTRAN's calling convention. Use looks like this:

extern fortran int FUNCTION(int *a, int *b, int *c);

(variables are passed by reference in FORTRAN).

You can also export a function to be called from FORTRAN like so:

fortran int FUNCTION2(int *a, int *b, int *c)
{
    /* your code here */
}

I actually used it to call into QBX (BASIC), which uses almost exactly the same calling convention. The pascal keyword was better for this purpose; otherwise arguments come in backwards.

like image 169
Joshua Avatar answered Oct 22 '22 23:10

Joshua