From patchwork Fri Nov 5 21:12:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandra Loosemore X-Patchwork-Id: 47137 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE4793857C77 for ; Fri, 5 Nov 2021 21:13:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 6F1A3385840A; Fri, 5 Nov 2021 21:13:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6F1A3385840A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: iVuZtEFfCubFqpdTxVYVeJEWvTUUs1+lq96P5ssPe5z6/DpNl/XSnaKr1VLtmronH+jI/KXkYe olM49+kNa1s+Q/QlOvJBrDhfMKIl/vmAJZq7iNhU1XMRHOVC/tE6uyHLOZOd0kdkBHj0Mg/Oxl aGjkPB85dRD5DJOeVQ7O0eOXMXVMPYFcVDPHJQNcNBPHP1ytpVVO9Pn3BVsGromoYmd+VmaQF6 WhToHxIXNhXcTJ104qlLg9io7AAEyj6cdKGOq6cNJzzKndaeBsQDhjOzZpS0DkIjEMi9Q/t8U+ 2CLAEMcu/x8bHZofY7W3d2Yp X-IronPort-AV: E=Sophos;i="5.87,212,1631606400"; d="scan'208";a="68124705" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 05 Nov 2021 13:12:59 -0800 IronPort-SDR: jn5gMs7h8zpwSOhsTyPo01dYCRWwfyER2i3MgeFJGx9BtRrWyI9NndVvF4CfVgdiL45pTAxmIA ++l7axqmCm+TQN81e3bd/xbdu4JUtTuZRkbCfuNJUwXESX5vSSbvOD+O9TSdn/PZLqHNsnIRmH JNhHgbwMvPGN9JpaGq387vTXFTqQn3nZiWpS7+mNq1LICGzXIA8yDVY9u4B8/TRTxQjKfLF19u Z0yduVI4flGWU6sj+sbEE5FSIWqvYAp8c1a6p4PE5QeiSWl9naOsUS80u7yb5lbH9pDByLx4aE euo= To: "fortran@gcc.gnu.org" , "gcc-patches@gcc.gnu.org" From: Sandra Loosemore Subject: [committed] Fortran: Add more documentation for mixed-language programming Message-ID: <8d48a7ce-3d8b-24a4-9964-bc03bd7909b5@codesourcery.com> Date: Fri, 5 Nov 2021 15:12:54 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 Content-Language: en-US X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" I was recently pinged about PR35276. It's an old issue, but a couple of the concerns raised there haven't been fixed yet, so I've checked in this patch to fill in the gaps. -Sandra commit b8bf685ed44dba9bd4bbd600bc8bc2be0a2abb1b Author: Sandra Loosemore Date: Fri Nov 5 14:01:03 2021 -0700 Fortran: Add more documentation for mixed-language programming [PR35276] 2021-11-05 Sandra Loosemore PR fortran/35276 gcc/fortran/ * gfortran.texi (Mixed-Language Programming): Talk about C++, and how to link. diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index f3a961e..3264709 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -2718,11 +2718,23 @@ reading from the position marked previously. * Naming and argument-passing conventions:: @end menu -This chapter is about mixed-language interoperability, but also applies -if one links Fortran code compiled by different compilers. In most cases, -use of the C Binding features of the Fortran 2003 standard is sufficient, -and their use is highly recommended. - +This chapter is about mixed-language interoperability, but also +applies if you link Fortran code compiled by different compilers. In +most cases, use of the C Binding features of the Fortran 2003 and +later standards is sufficient. + +For example, it is possible to mix Fortran code with C++ code as well +as C, if you declare the interface functions as @code{extern "C"} on +the C++ side and @code{BIND(C)} on the Fortran side, and follow the +rules for interoperability with C. Note that you cannot manipulate +C++ class objects in Fortran or vice versa except as opaque pointers. + +You can use the @command{gfortran} command to link both Fortran and +non-Fortran code into the same program, or you can use @command{gcc} +or @command{g++} if you also add an explicit @option{-lgfortran} option +to link with the Fortran library. If your main program is written in +C or some other language instead of Fortran, see +@ref{Non-Fortran Main Program}, below. @node Interoperability with C @section Interoperability with C