public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Fortran subroutine names containing underscore?
@ 1998-05-07 10:22 Bengt Lund-Jensen
  1998-05-07 14:13 ` Mumit Khan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bengt Lund-Jensen @ 1998-05-07 10:22 UTC (permalink / raw)
  To: egcs; +Cc: lund

First of all: Thanks for a nice compiler set!!

However, with the risk of asking a stupid question:

Why does Fortran subroutine names containing an underscore (e.g FOO_BAR)
translate into a name ending in 2 __  (i.e. foo_bar__) while
names not containing any underscore translates to names only containing
1 underscore (i.e. FOOBAR  becomes foobar_ ) ?

(This difference makes life rather hard when combining Fortran and C software)

I am compiling with 'g77 -g -c'  using the egcs-1.0.2 compiler set under 
Linux RH-5.0

Or to rephrase my question:
How can I get g77 to only add one underscore at the end for all 
Fortran subroutine/function names (even the ones containing an underscore in 
the middle)?  


                    Regards,  Bengt Lund-Jensen



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Fortran subroutine names containing underscore?
  1998-05-07 10:22 Fortran subroutine names containing underscore? Bengt Lund-Jensen
@ 1998-05-07 14:13 ` Mumit Khan
  1998-05-07 15:31 ` Dave Love
  1998-05-07 18:42 ` Craig Burley
  2 siblings, 0 replies; 4+ messages in thread
From: Mumit Khan @ 1998-05-07 14:13 UTC (permalink / raw)
  To: Bengt Lund-Jensen; +Cc: egcs

Bengt Lund-Jensen <lund@particle.kth.se> writes:
> 

[...]

> Or to rephrase my question:
> How can I get g77 to only add one underscore at the end for all 
> Fortran subroutine/function names (even the ones containing an underscore in 
> the middle)?  

G77 documentation files is usually a good place to look for answers to 
such questions (``info g77''). This behaviour is documented in the g77 
files, so please check that for detailed info. Basically, this is to 
remain compatible with f2c translated files, and if you don't about 
that, simple use -fno-second-underscore. I believe this option was 
added in 0.5.19 (or was it 0.5.18?) timeframe, and older versions will 
choke on it.

Mumit


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Fortran subroutine names containing underscore?
  1998-05-07 10:22 Fortran subroutine names containing underscore? Bengt Lund-Jensen
  1998-05-07 14:13 ` Mumit Khan
@ 1998-05-07 15:31 ` Dave Love
  1998-05-07 18:42 ` Craig Burley
  2 siblings, 0 replies; 4+ messages in thread
From: Dave Love @ 1998-05-07 15:31 UTC (permalink / raw)
  To: Bengt Lund-Jensen; +Cc: egcs

>>>>> "Bengt" == Bengt Lund-Jensen <lund@particle.kth.se> writes:

 Bengt> Why does Fortran subroutine names containing an underscore
 Bengt> (e.g FOO_BAR) translate into a name ending in 2 __
 Bengt> (i.e. foo_bar__) while names not containing any underscore
 Bengt> translates to names only containing 1 underscore (i.e. FOOBAR
 Bengt> becomes foobar_ ) ?

f2c compatibility.  AFAIR there are clues as to why f2c does this
either in its changes file or its source.

 Bengt> How can I get g77 to only add one underscore at the end for
 Bengt> all Fortran subroutine/function names (even the ones
 Bengt> containing an underscore in the middle)?

`i underscore' in the g77 info will find the information.  How can we
make it easier to find?



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Fortran subroutine names containing underscore?
  1998-05-07 10:22 Fortran subroutine names containing underscore? Bengt Lund-Jensen
  1998-05-07 14:13 ` Mumit Khan
  1998-05-07 15:31 ` Dave Love
@ 1998-05-07 18:42 ` Craig Burley
  2 siblings, 0 replies; 4+ messages in thread
From: Craig Burley @ 1998-05-07 18:42 UTC (permalink / raw)
  To: lund; +Cc: egcs

>Why does Fortran subroutine names containing an underscore (e.g FOO_BAR)
>translate into a name ending in 2 __  (i.e. foo_bar__) while
>names not containing any underscore translates to names only containing
>1 underscore (i.e. FOOBAR  becomes foobar_ ) ?

Because g77 defaults to being object-compatible with f2c, partly
because it uses the same run-time library, libf2c.  The
node "Debugging and Interfacing" (IIRC) in the g77 docs explains
this, I think.

>(This difference makes life rather hard when combining Fortran and C software)

That's the easiest difference to cope with, though, currently.  ;-)

>How can I get g77 to only add one underscore at the end for all 
>Fortran subroutine/function names (even the ones containing an underscore in 
>the middle)?  

See `-fno-second-underscore', with appropriate cross-references
and related warnings about what *else* might happen.

Put simply: it is better to have the linker refuse to produce
an executable than silently produce one that does not compute
the correct results.  And the latter is a very real danger if
you focus exclusively on getting external names to "match" without
carefully checking whether language, interface, and calling
conventions *also* match.

Generally it is safest to write explicit wrappers, but for lots
of cases, getting the names to match is all that is needed.
The problem is predicting those cases properly, and coping with
the risks of predicting wrongly.

        tq vm, (burley)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-05-07 18:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-07 10:22 Fortran subroutine names containing underscore? Bengt Lund-Jensen
1998-05-07 14:13 ` Mumit Khan
1998-05-07 15:31 ` Dave Love
1998-05-07 18:42 ` Craig Burley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).