Next: , Previous: Directory Options, Up: Invoking GFORTRAN


4.6 Options for Code Generation Conventions

These machine-independent options control the interface conventions used in code generation.

Most of them have both positive and negative forms; the negative form of -ffoo would be -fno-foo. In the table below, only one of the forms is listed—the one which is not the default. You can figure out the other form by either removing no- or adding it.

-fno-automatic
Treat each program unit as if the SAVE statement was specified for every local variable and array referenced in it. Does not affect common blocks. (Some Fortran compilers provide this option under the name -static.)


-ff2c
Generate code designed to be compatible with code generated by g77 and f2c.

The calling conventions used by g77 (originally implemented in f2c) require functions that return type default REAL to actually return the C type double, and functions that return type COMPLEX to return the values via an extra argument in the calling sequence that points to where to store the return value. Under the default GNU calling conventions, such functions simply return their results as they would in GNU C – default REAL functions return the C type float, and COMPLEX functions return the GNU C type complex. Additionally, this option implies the -fsecond-underscore option, unless -fno-second-underscore is explicitly requested.

This does not affect the generation of code that interfaces with the libgfortran library.

Caution: It is not a good idea to mix Fortran code compiled with -ff2c with code compiled with the default -fno-f2c calling conventions as, calling COMPLEX or default REAL functions between program parts which were compiled with different calling conventions will break at execution time.

Caution: This will break code which passes intrinsic functions of type default REAL or COMPLEX as actual arguments, as the library implementations use the -fno-f2c calling conventions.


-fno-underscoring
Do not transform names of entities specified in the Fortran source file by appending underscores to them.

With -funderscoring in effect, gfortran appends one underscore to external names with no underscores.

This is done to ensure compatibility with code produced by many UNIX Fortran compilers.

Caution: The default behavior of gfortran is incompatible with f2c and g77, please use the -ff2c option if you want object files compiled with gfortran to be compatible with object code created with these tools.

Use of -fno-underscoring is not recommended unless you are experimenting with issues such as integration of (GNU) Fortran into existing system environments (vis-a-vis existing libraries, tools, and so on).

For example, with -funderscoring, and assuming other defaults like -fcase-lower and that `j()' and `max_count()' are external functions while `my_var' and `lvar' are local variables, a statement like

          I = J() + MAX_COUNT (MY_VAR, LVAR)
     

is implemented as something akin to:

          i = j_() + max_count__(&my_var__, &lvar);
     

With -fno-underscoring, the same statement is implemented as:

          i = j() + max_count(&my_var, &lvar);
     

Use of -fno-underscoring allows direct specification of user-defined names while debugging and when interfacing gfortran code with other languages.

Note that just because the names match does not mean that the interface implemented by gfortran for an external name matches the interface implemented by some other language for that same name. That is, getting code produced by gfortran to link to code produced by some other compiler using this or any other method can be only a small part of the overall solution—getting the code generated by both compilers to agree on issues other than naming can require significant effort, and, unlike naming disagreements, linkers normally cannot detect disagreements in these other areas.

Also, note that with -fno-underscoring, the lack of appended underscores introduces the very real possibility that a user-defined external name will conflict with a name in a system library, which could make finding unresolved-reference bugs quite difficult in some cases—they might occur at program run time, and show up only as buggy behavior at run time.

In future versions of gfortran we hope to improve naming and linking issues so that debugging always involves using the names as they appear in the source, even if the names as seen by the linker are mangled to prevent accidental linking between procedures with incompatible interfaces.


-fsecond-underscore
By default, gfortran appends an underscore to external names. If this option is used gfortran appends two underscores to names with underscores and one underscore to external names with no underscores. (gfortran also appends two underscores to internal names with underscores to avoid naming collisions with external names.

This option has no effect if -fno-underscoring is in effect. It is implied by the -ff2c option.

Otherwise, with this option, an external name such as `MAX_COUNT' is implemented as a reference to the link-time external symbol `max_count__', instead of `max_count_'. This is required for compatibility with g77 and f2c, and is implied by use of the -ff2c option.


-fbounds-check
Enable generation of run-time checks for array subscripts and against the declared minimum and maximum values. It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds.

In the future this may also include other forms of checking, eg. checking substring references.


-fmax-stack-var-size=n
This option specifies the size in bytes of the largest array that will be put on the stack.

This option currently only affects local arrays declared with constant bounds, and may not apply to all character variables. Future versions of gfortran may improve this behavior.

The default value for n is 32768.


-fpackderived
This option tells gfortran to pack derived type members as closely as possible. Code compiled with this option is likely to be incompatible with code compiled without this option, and may execute slower.


-frepack-arrays
In some circumstances gfortran may pass assumed shape array sections via a descriptor describing a discontiguous area of memory. This option adds code to the function prologue to repack the data into a contiguous block at runtime.

This should result in faster accesses to the array. However it can introduce significant overhead to the function call, especially when the passed data is discontiguous.

See Options for Code Generation Conventions, for information on more options offered by the GBE shared by gfortran gcc and other GNU compilers.