gfortran.texi 165 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492
  1. \input texinfo @c -*-texinfo-*-
  2. @c %**start of header
  3. @setfilename gfortran.info
  4. @set copyrights-gfortran 1999-2015
  5. @include gcc-common.texi
  6. @settitle The GNU Fortran Compiler
  7. @c Create a separate index for command line options
  8. @defcodeindex op
  9. @c Merge the standard indexes into a single one.
  10. @syncodeindex fn cp
  11. @syncodeindex vr cp
  12. @syncodeindex ky cp
  13. @syncodeindex pg cp
  14. @syncodeindex tp cp
  15. @c TODO: The following "Part" definitions are included here temporarily
  16. @c until they are incorporated into the official Texinfo distribution.
  17. @c They borrow heavily from Texinfo's \unnchapentry definitions.
  18. @tex
  19. \gdef\part#1#2{%
  20. \pchapsepmacro
  21. \gdef\thischapter{}
  22. \begingroup
  23. \vglue\titlepagetopglue
  24. \titlefonts \rm
  25. \leftline{Part #1:@* #2}
  26. \vskip4pt \hrule height 4pt width \hsize \vskip4pt
  27. \endgroup
  28. \writetocentry{part}{#2}{#1}
  29. }
  30. \gdef\blankpart{%
  31. \writetocentry{blankpart}{}{}
  32. }
  33. % Part TOC-entry definition for summary contents.
  34. \gdef\dosmallpartentry#1#2#3#4{%
  35. \vskip .5\baselineskip plus.2\baselineskip
  36. \begingroup
  37. \let\rm=\bf \rm
  38. \tocentry{Part #2: #1}{\doshortpageno\bgroup#4\egroup}
  39. \endgroup
  40. }
  41. \gdef\dosmallblankpartentry#1#2#3#4{%
  42. \vskip .5\baselineskip plus.2\baselineskip
  43. }
  44. % Part TOC-entry definition for regular contents. This has to be
  45. % equated to an existing entry to not cause problems when the PDF
  46. % outline is created.
  47. \gdef\dopartentry#1#2#3#4{%
  48. \unnchapentry{Part #2: #1}{}{#3}{#4}
  49. }
  50. \gdef\doblankpartentry#1#2#3#4{}
  51. @end tex
  52. @c %**end of header
  53. @c Use with @@smallbook.
  54. @c %** start of document
  55. @c Cause even numbered pages to be printed on the left hand side of
  56. @c the page and odd numbered pages to be printed on the right hand
  57. @c side of the page. Using this, you can print on both sides of a
  58. @c sheet of paper and have the text on the same part of the sheet.
  59. @c The text on right hand pages is pushed towards the right hand
  60. @c margin and the text on left hand pages is pushed toward the left
  61. @c hand margin.
  62. @c (To provide the reverse effect, set bindingoffset to -0.75in.)
  63. @c @tex
  64. @c \global\bindingoffset=0.75in
  65. @c \global\normaloffset =0.75in
  66. @c @end tex
  67. @copying
  68. Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
  69. Permission is granted to copy, distribute and/or modify this document
  70. under the terms of the GNU Free Documentation License, Version 1.3 or
  71. any later version published by the Free Software Foundation; with the
  72. Invariant Sections being ``Funding Free Software'', the Front-Cover
  73. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  74. (see below). A copy of the license is included in the section entitled
  75. ``GNU Free Documentation License''.
  76. (a) The FSF's Front-Cover Text is:
  77. A GNU Manual
  78. (b) The FSF's Back-Cover Text is:
  79. You have freedom to copy and modify this GNU Manual, like GNU
  80. software. Copies published by the Free Software Foundation raise
  81. funds for GNU development.
  82. @end copying
  83. @ifinfo
  84. @dircategory Software development
  85. @direntry
  86. * gfortran: (gfortran). The GNU Fortran Compiler.
  87. @end direntry
  88. This file documents the use and the internals of
  89. the GNU Fortran compiler, (@command{gfortran}).
  90. Published by the Free Software Foundation
  91. 51 Franklin Street, Fifth Floor
  92. Boston, MA 02110-1301 USA
  93. @insertcopying
  94. @end ifinfo
  95. @setchapternewpage odd
  96. @titlepage
  97. @title Using GNU Fortran
  98. @versionsubtitle
  99. @author The @t{gfortran} team
  100. @page
  101. @vskip 0pt plus 1filll
  102. Published by the Free Software Foundation@*
  103. 51 Franklin Street, Fifth Floor@*
  104. Boston, MA 02110-1301, USA@*
  105. @c Last printed ??ber, 19??.@*
  106. @c Printed copies are available for $? each.@*
  107. @c ISBN ???
  108. @sp 1
  109. @insertcopying
  110. @end titlepage
  111. @c TODO: The following "Part" definitions are included here temporarily
  112. @c until they are incorporated into the official Texinfo distribution.
  113. @tex
  114. \global\let\partentry=\dosmallpartentry
  115. \global\let\blankpartentry=\dosmallblankpartentry
  116. @end tex
  117. @summarycontents
  118. @tex
  119. \global\let\partentry=\dopartentry
  120. \global\let\blankpartentry=\doblankpartentry
  121. @end tex
  122. @contents
  123. @page
  124. @c ---------------------------------------------------------------------
  125. @c TexInfo table of contents.
  126. @c ---------------------------------------------------------------------
  127. @ifnottex
  128. @node Top
  129. @top Introduction
  130. @cindex Introduction
  131. This manual documents the use of @command{gfortran},
  132. the GNU Fortran compiler. You can find in this manual how to invoke
  133. @command{gfortran}, as well as its features and incompatibilities.
  134. @ifset DEVELOPMENT
  135. @emph{Warning:} This document, and the compiler it describes, are still
  136. under development. While efforts are made to keep it up-to-date, it might
  137. not accurately reflect the status of the most recent GNU Fortran compiler.
  138. @end ifset
  139. @comment
  140. @comment When you add a new menu item, please keep the right hand
  141. @comment aligned to the same column. Do not use tabs. This provides
  142. @comment better formatting.
  143. @comment
  144. @menu
  145. * Introduction::
  146. Part I: Invoking GNU Fortran
  147. * Invoking GNU Fortran:: Command options supported by @command{gfortran}.
  148. * Runtime:: Influencing runtime behavior with environment variables.
  149. Part II: Language Reference
  150. * Fortran 2003 and 2008 status:: Fortran 2003 and 2008 features supported by GNU Fortran.
  151. * Compiler Characteristics:: User-visible implementation details.
  152. * Extensions:: Language extensions implemented by GNU Fortran.
  153. * Mixed-Language Programming:: Interoperability with C
  154. * Coarray Programming::
  155. * Intrinsic Procedures:: Intrinsic procedures supported by GNU Fortran.
  156. * Intrinsic Modules:: Intrinsic modules supported by GNU Fortran.
  157. * Contributing:: How you can help.
  158. * Copying:: GNU General Public License says
  159. how you can copy and share GNU Fortran.
  160. * GNU Free Documentation License::
  161. How you can copy and share this manual.
  162. * Funding:: How to help assure continued work for free software.
  163. * Option Index:: Index of command line options
  164. * Keyword Index:: Index of concepts
  165. @end menu
  166. @end ifnottex
  167. @c ---------------------------------------------------------------------
  168. @c Introduction
  169. @c ---------------------------------------------------------------------
  170. @node Introduction
  171. @chapter Introduction
  172. @c The following duplicates the text on the TexInfo table of contents.
  173. @iftex
  174. This manual documents the use of @command{gfortran}, the GNU Fortran
  175. compiler. You can find in this manual how to invoke @command{gfortran},
  176. as well as its features and incompatibilities.
  177. @ifset DEVELOPMENT
  178. @emph{Warning:} This document, and the compiler it describes, are still
  179. under development. While efforts are made to keep it up-to-date, it
  180. might not accurately reflect the status of the most recent GNU Fortran
  181. compiler.
  182. @end ifset
  183. @end iftex
  184. The GNU Fortran compiler front end was
  185. designed initially as a free replacement for,
  186. or alternative to, the Unix @command{f95} command;
  187. @command{gfortran} is the command you will use to invoke the compiler.
  188. @menu
  189. * About GNU Fortran:: What you should know about the GNU Fortran compiler.
  190. * GNU Fortran and GCC:: You can compile Fortran, C, or other programs.
  191. * Preprocessing and conditional compilation:: The Fortran preprocessor
  192. * GNU Fortran and G77:: Why we chose to start from scratch.
  193. * Project Status:: Status of GNU Fortran, roadmap, proposed extensions.
  194. * Standards:: Standards supported by GNU Fortran.
  195. @end menu
  196. @c ---------------------------------------------------------------------
  197. @c About GNU Fortran
  198. @c ---------------------------------------------------------------------
  199. @node About GNU Fortran
  200. @section About GNU Fortran
  201. The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards
  202. completely, parts of the Fortran 2003 and Fortran 2008 standards, and
  203. several vendor extensions. The development goal is to provide the
  204. following features:
  205. @itemize @bullet
  206. @item
  207. Read a user's program,
  208. stored in a file and containing instructions written
  209. in Fortran 77, Fortran 90, Fortran 95, Fortran 2003 or Fortran 2008.
  210. This file contains @dfn{source code}.
  211. @item
  212. Translate the user's program into instructions a computer
  213. can carry out more quickly than it takes to translate the
  214. instructions in the first
  215. place. The result after compilation of a program is
  216. @dfn{machine code},
  217. code designed to be efficiently translated and processed
  218. by a machine such as your computer.
  219. Humans usually are not as good writing machine code
  220. as they are at writing Fortran (or C++, Ada, or Java),
  221. because it is easy to make tiny mistakes writing machine code.
  222. @item
  223. Provide the user with information about the reasons why
  224. the compiler is unable to create a binary from the source code.
  225. Usually this will be the case if the source code is flawed.
  226. The Fortran 90 standard requires that the compiler can point out
  227. mistakes to the user.
  228. An incorrect usage of the language causes an @dfn{error message}.
  229. The compiler will also attempt to diagnose cases where the
  230. user's program contains a correct usage of the language,
  231. but instructs the computer to do something questionable.
  232. This kind of diagnostics message is called a @dfn{warning message}.
  233. @item
  234. Provide optional information about the translation passes
  235. from the source code to machine code.
  236. This can help a user of the compiler to find the cause of
  237. certain bugs which may not be obvious in the source code,
  238. but may be more easily found at a lower level compiler output.
  239. It also helps developers to find bugs in the compiler itself.
  240. @item
  241. Provide information in the generated machine code that can
  242. make it easier to find bugs in the program (using a debugging tool,
  243. called a @dfn{debugger}, such as the GNU Debugger @command{gdb}).
  244. @item
  245. Locate and gather machine code already generated to
  246. perform actions requested by statements in the user's program.
  247. This machine code is organized into @dfn{modules} and is located
  248. and @dfn{linked} to the user program.
  249. @end itemize
  250. The GNU Fortran compiler consists of several components:
  251. @itemize @bullet
  252. @item
  253. A version of the @command{gcc} command
  254. (which also might be installed as the system's @command{cc} command)
  255. that also understands and accepts Fortran source code.
  256. The @command{gcc} command is the @dfn{driver} program for
  257. all the languages in the GNU Compiler Collection (GCC);
  258. With @command{gcc},
  259. you can compile the source code of any language for
  260. which a front end is available in GCC.
  261. @item
  262. The @command{gfortran} command itself,
  263. which also might be installed as the
  264. system's @command{f95} command.
  265. @command{gfortran} is just another driver program,
  266. but specifically for the Fortran compiler only.
  267. The difference with @command{gcc} is that @command{gfortran}
  268. will automatically link the correct libraries to your program.
  269. @item
  270. A collection of run-time libraries.
  271. These libraries contain the machine code needed to support
  272. capabilities of the Fortran language that are not directly
  273. provided by the machine code generated by the
  274. @command{gfortran} compilation phase,
  275. such as intrinsic functions and subroutines,
  276. and routines for interaction with files and the operating system.
  277. @c and mechanisms to spawn,
  278. @c unleash and pause threads in parallelized code.
  279. @item
  280. The Fortran compiler itself, (@command{f951}).
  281. This is the GNU Fortran parser and code generator,
  282. linked to and interfaced with the GCC backend library.
  283. @command{f951} ``translates'' the source code to
  284. assembler code. You would typically not use this
  285. program directly;
  286. instead, the @command{gcc} or @command{gfortran} driver
  287. programs will call it for you.
  288. @end itemize
  289. @c ---------------------------------------------------------------------
  290. @c GNU Fortran and GCC
  291. @c ---------------------------------------------------------------------
  292. @node GNU Fortran and GCC
  293. @section GNU Fortran and GCC
  294. @cindex GNU Compiler Collection
  295. @cindex GCC
  296. GNU Fortran is a part of GCC, the @dfn{GNU Compiler Collection}. GCC
  297. consists of a collection of front ends for various languages, which
  298. translate the source code into a language-independent form called
  299. @dfn{GENERIC}. This is then processed by a common middle end which
  300. provides optimization, and then passed to one of a collection of back
  301. ends which generate code for different computer architectures and
  302. operating systems.
  303. Functionally, this is implemented with a driver program (@command{gcc})
  304. which provides the command-line interface for the compiler. It calls
  305. the relevant compiler front-end program (e.g., @command{f951} for
  306. Fortran) for each file in the source code, and then calls the assembler
  307. and linker as appropriate to produce the compiled output. In a copy of
  308. GCC which has been compiled with Fortran language support enabled,
  309. @command{gcc} will recognize files with @file{.f}, @file{.for}, @file{.ftn},
  310. @file{.f90}, @file{.f95}, @file{.f03} and @file{.f08} extensions as
  311. Fortran source code, and compile it accordingly. A @command{gfortran}
  312. driver program is also provided, which is identical to @command{gcc}
  313. except that it automatically links the Fortran runtime libraries into the
  314. compiled program.
  315. Source files with @file{.f}, @file{.for}, @file{.fpp}, @file{.ftn}, @file{.F},
  316. @file{.FOR}, @file{.FPP}, and @file{.FTN} extensions are treated as fixed form.
  317. Source files with @file{.f90}, @file{.f95}, @file{.f03}, @file{.f08},
  318. @file{.F90}, @file{.F95}, @file{.F03} and @file{.F08} extensions are
  319. treated as free form. The capitalized versions of either form are run
  320. through preprocessing. Source files with the lower case @file{.fpp}
  321. extension are also run through preprocessing.
  322. This manual specifically documents the Fortran front end, which handles
  323. the programming language's syntax and semantics. The aspects of GCC
  324. which relate to the optimization passes and the back-end code generation
  325. are documented in the GCC manual; see
  326. @ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
  327. The two manuals together provide a complete reference for the GNU
  328. Fortran compiler.
  329. @c ---------------------------------------------------------------------
  330. @c Preprocessing and conditional compilation
  331. @c ---------------------------------------------------------------------
  332. @node Preprocessing and conditional compilation
  333. @section Preprocessing and conditional compilation
  334. @cindex CPP
  335. @cindex FPP
  336. @cindex Conditional compilation
  337. @cindex Preprocessing
  338. @cindex preprocessor, include file handling
  339. Many Fortran compilers including GNU Fortran allow passing the source code
  340. through a C preprocessor (CPP; sometimes also called the Fortran preprocessor,
  341. FPP) to allow for conditional compilation. In the case of GNU Fortran,
  342. this is the GNU C Preprocessor in the traditional mode. On systems with
  343. case-preserving file names, the preprocessor is automatically invoked if the
  344. filename extension is @file{.F}, @file{.FOR}, @file{.FTN}, @file{.fpp},
  345. @file{.FPP}, @file{.F90}, @file{.F95}, @file{.F03} or @file{.F08}. To manually
  346. invoke the preprocessor on any file, use @option{-cpp}, to disable
  347. preprocessing on files where the preprocessor is run automatically, use
  348. @option{-nocpp}.
  349. If a preprocessed file includes another file with the Fortran @code{INCLUDE}
  350. statement, the included file is not preprocessed. To preprocess included
  351. files, use the equivalent preprocessor statement @code{#include}.
  352. If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
  353. is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
  354. @code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
  355. compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
  356. While CPP is the de-facto standard for preprocessing Fortran code,
  357. Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
  358. Conditional Compilation, which is not widely used and not directly
  359. supported by the GNU Fortran compiler. You can use the program coco
  360. to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}).
  361. @c ---------------------------------------------------------------------
  362. @c GNU Fortran and G77
  363. @c ---------------------------------------------------------------------
  364. @node GNU Fortran and G77
  365. @section GNU Fortran and G77
  366. @cindex Fortran 77
  367. @cindex @command{g77}
  368. The GNU Fortran compiler is the successor to @command{g77}, the Fortran
  369. 77 front end included in GCC prior to version 4. It is an entirely new
  370. program that has been designed to provide Fortran 95 support and
  371. extensibility for future Fortran language standards, as well as providing
  372. backwards compatibility for Fortran 77 and nearly all of the GNU language
  373. extensions supported by @command{g77}.
  374. @c ---------------------------------------------------------------------
  375. @c Project Status
  376. @c ---------------------------------------------------------------------
  377. @node Project Status
  378. @section Project Status
  379. @quotation
  380. As soon as @command{gfortran} can parse all of the statements correctly,
  381. it will be in the ``larva'' state.
  382. When we generate code, the ``puppa'' state.
  383. When @command{gfortran} is done,
  384. we'll see if it will be a beautiful butterfly,
  385. or just a big bug....
  386. --Andy Vaught, April 2000
  387. @end quotation
  388. The start of the GNU Fortran 95 project was announced on
  389. the GCC homepage in March 18, 2000
  390. (even though Andy had already been working on it for a while,
  391. of course).
  392. The GNU Fortran compiler is able to compile nearly all
  393. standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
  394. including a number of standard and non-standard extensions, and can be
  395. used on real-world programs. In particular, the supported extensions
  396. include OpenMP, Cray-style pointers, and several Fortran 2003 and Fortran
  397. 2008 features, including TR 15581. However, it is still under
  398. development and has a few remaining rough edges.
  399. There also is initial support for OpenACC.
  400. Note that this is an experimental feature, incomplete, and subject to
  401. change in future versions of GCC. See
  402. @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
  403. At present, the GNU Fortran compiler passes the
  404. @uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
  405. NIST Fortran 77 Test Suite}, and produces acceptable results on the
  406. @uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
  407. It also provides respectable performance on
  408. the @uref{http://www.polyhedron.com/fortran-compiler-comparisons/polyhedron-benchmark-suite,
  409. Polyhedron Fortran
  410. compiler benchmarks} and the
  411. @uref{http://www.netlib.org/benchmark/livermore,
  412. Livermore Fortran Kernels test}. It has been used to compile a number of
  413. large real-world programs, including
  414. @uref{http://hirlam.org/, the HARMONIE and HIRLAM weather forecasting code} and
  415. @uref{http://physical-chemistry.scb.uwa.edu.au/tonto/wiki/index.php/Main_Page,
  416. the Tonto quantum chemistry package}; see
  417. @url{https://gcc.gnu.org/@/wiki/@/GfortranApps} for an extended list.
  418. Among other things, the GNU Fortran compiler is intended as a replacement
  419. for G77. At this point, nearly all programs that could be compiled with
  420. G77 can be compiled with GNU Fortran, although there are a few minor known
  421. regressions.
  422. The primary work remaining to be done on GNU Fortran falls into three
  423. categories: bug fixing (primarily regarding the treatment of invalid code
  424. and providing useful error messages), improving the compiler optimizations
  425. and the performance of compiled code, and extending the compiler to support
  426. future standards---in particular, Fortran 2003 and Fortran 2008.
  427. @c ---------------------------------------------------------------------
  428. @c Standards
  429. @c ---------------------------------------------------------------------
  430. @node Standards
  431. @section Standards
  432. @cindex Standards
  433. @menu
  434. * Varying Length Character Strings::
  435. @end menu
  436. The GNU Fortran compiler implements
  437. ISO/IEC 1539:1997 (Fortran 95). As such, it can also compile essentially all
  438. standard-compliant Fortran 90 and Fortran 77 programs. It also supports
  439. the ISO/IEC TR-15581 enhancements to allocatable arrays.
  440. GNU Fortran also have a partial support for ISO/IEC 1539-1:2004 (Fortran
  441. 2003), ISO/IEC 1539-1:2010 (Fortran 2008), the Technical Specification
  442. @code{Further Interoperability of Fortran with C} (ISO/IEC TS 29113:2012).
  443. Full support of those standards and future Fortran standards is planned.
  444. The current status of the support is can be found in the
  445. @ref{Fortran 2003 status}, @ref{Fortran 2008 status} and
  446. @ref{TS 29113 status} sections of the documentation.
  447. Additionally, the GNU Fortran compilers supports the OpenMP specification
  448. (version 4.0, @url{http://openmp.org/@/wp/@/openmp-specifications/}).
  449. There also is initial support for the OpenACC specification (targeting
  450. version 2.0, @uref{http://www.openacc.org/}).
  451. Note that this is an experimental feature, incomplete, and subject to
  452. change in future versions of GCC. See
  453. @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
  454. @node Varying Length Character Strings
  455. @subsection Varying Length Character Strings
  456. @cindex Varying length character strings
  457. @cindex Varying length strings
  458. @cindex strings, varying length
  459. The Fortran 95 standard specifies in Part 2 (ISO/IEC 1539-2:2000)
  460. varying length character strings. While GNU Fortran currently does not
  461. support such strings directly, there exist two Fortran implementations
  462. for them, which work with GNU Fortran. They can be found at
  463. @uref{http://www.fortran.com/@/iso_varying_string.f95} and at
  464. @uref{ftp://ftp.nag.co.uk/@/sc22wg5/@/ISO_VARYING_STRING/}.
  465. Deferred-length character strings of Fortran 2003 supports part of
  466. the features of @code{ISO_VARYING_STRING} and should be considered as
  467. replacement. (Namely, allocatable or pointers of the type
  468. @code{character(len=:)}.)
  469. @c =====================================================================
  470. @c PART I: INVOCATION REFERENCE
  471. @c =====================================================================
  472. @tex
  473. \part{I}{Invoking GNU Fortran}
  474. @end tex
  475. @c ---------------------------------------------------------------------
  476. @c Compiler Options
  477. @c ---------------------------------------------------------------------
  478. @include invoke.texi
  479. @c ---------------------------------------------------------------------
  480. @c Runtime
  481. @c ---------------------------------------------------------------------
  482. @node Runtime
  483. @chapter Runtime: Influencing runtime behavior with environment variables
  484. @cindex environment variable
  485. The behavior of the @command{gfortran} can be influenced by
  486. environment variables.
  487. Malformed environment variables are silently ignored.
  488. @menu
  489. * TMPDIR:: Directory for scratch files
  490. * GFORTRAN_STDIN_UNIT:: Unit number for standard input
  491. * GFORTRAN_STDOUT_UNIT:: Unit number for standard output
  492. * GFORTRAN_STDERR_UNIT:: Unit number for standard error
  493. * GFORTRAN_UNBUFFERED_ALL:: Do not buffer I/O for all units.
  494. * GFORTRAN_UNBUFFERED_PRECONNECTED:: Do not buffer I/O for preconnected units.
  495. * GFORTRAN_SHOW_LOCUS:: Show location for runtime errors
  496. * GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
  497. * GFORTRAN_DEFAULT_RECL:: Default record length for new files
  498. * GFORTRAN_LIST_SEPARATOR:: Separator for list output
  499. * GFORTRAN_CONVERT_UNIT:: Set endianness for unformatted I/O
  500. * GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
  501. @end menu
  502. @node TMPDIR
  503. @section @env{TMPDIR}---Directory for scratch files
  504. When opening a file with @code{STATUS='SCRATCH'}, GNU Fortran tries to
  505. create the file in one of the potential directories by testing each
  506. directory in the order below.
  507. @enumerate
  508. @item
  509. The environment variable @env{TMPDIR}, if it exists.
  510. @item
  511. On the MinGW target, the directory returned by the @code{GetTempPath}
  512. function. Alternatively, on the Cygwin target, the @env{TMP} and
  513. @env{TEMP} environment variables, if they exist, in that order.
  514. @item
  515. The @code{P_tmpdir} macro if it is defined, otherwise the directory
  516. @file{/tmp}.
  517. @end enumerate
  518. @node GFORTRAN_STDIN_UNIT
  519. @section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
  520. This environment variable can be used to select the unit number
  521. preconnected to standard input. This must be a positive integer.
  522. The default value is 5.
  523. @node GFORTRAN_STDOUT_UNIT
  524. @section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
  525. This environment variable can be used to select the unit number
  526. preconnected to standard output. This must be a positive integer.
  527. The default value is 6.
  528. @node GFORTRAN_STDERR_UNIT
  529. @section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
  530. This environment variable can be used to select the unit number
  531. preconnected to standard error. This must be a positive integer.
  532. The default value is 0.
  533. @node GFORTRAN_UNBUFFERED_ALL
  534. @section @env{GFORTRAN_UNBUFFERED_ALL}---Do not buffer I/O on all units
  535. This environment variable controls whether all I/O is unbuffered. If
  536. the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
  537. unbuffered. This will slow down small sequential reads and writes. If
  538. the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
  539. This is the default.
  540. @node GFORTRAN_UNBUFFERED_PRECONNECTED
  541. @section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Do not buffer I/O on preconnected units
  542. The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
  543. whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered. If
  544. the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered. This
  545. will slow down small sequential reads and writes. If the first letter
  546. is @samp{n}, @samp{N} or @samp{0}, I/O is buffered. This is the default.
  547. @node GFORTRAN_SHOW_LOCUS
  548. @section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
  549. If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
  550. line numbers for runtime errors are printed. If the first letter is
  551. @samp{n}, @samp{N} or @samp{0}, do not print filename and line numbers
  552. for runtime errors. The default is to print the location.
  553. @node GFORTRAN_OPTIONAL_PLUS
  554. @section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
  555. If the first letter is @samp{y}, @samp{Y} or @samp{1},
  556. a plus sign is printed
  557. where permitted by the Fortran standard. If the first letter
  558. is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
  559. in most cases. Default is not to print plus signs.
  560. @node GFORTRAN_DEFAULT_RECL
  561. @section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files
  562. This environment variable specifies the default record length, in
  563. bytes, for files which are opened without a @code{RECL} tag in the
  564. @code{OPEN} statement. This must be a positive integer. The
  565. default value is 1073741824 bytes (1 GB).
  566. @node GFORTRAN_LIST_SEPARATOR
  567. @section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
  568. This environment variable specifies the separator when writing
  569. list-directed output. It may contain any number of spaces and
  570. at most one comma. If you specify this on the command line,
  571. be sure to quote spaces, as in
  572. @smallexample
  573. $ GFORTRAN_LIST_SEPARATOR=' , ' ./a.out
  574. @end smallexample
  575. when @command{a.out} is the compiled Fortran program that you want to run.
  576. Default is a single space.
  577. @node GFORTRAN_CONVERT_UNIT
  578. @section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
  579. By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
  580. to change the representation of data for unformatted files.
  581. The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
  582. @smallexample
  583. GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
  584. mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
  585. exception: mode ':' unit_list | unit_list ;
  586. unit_list: unit_spec | unit_list unit_spec ;
  587. unit_spec: INTEGER | INTEGER '-' INTEGER ;
  588. @end smallexample
  589. The variable consists of an optional default mode, followed by
  590. a list of optional exceptions, which are separated by semicolons
  591. from the preceding default and each other. Each exception consists
  592. of a format and a comma-separated list of units. Valid values for
  593. the modes are the same as for the @code{CONVERT} specifier:
  594. @itemize @w{}
  595. @item @code{NATIVE} Use the native format. This is the default.
  596. @item @code{SWAP} Swap between little- and big-endian.
  597. @item @code{LITTLE_ENDIAN} Use the little-endian format
  598. for unformatted files.
  599. @item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
  600. @end itemize
  601. A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
  602. Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
  603. @itemize @w{}
  604. @item @code{'big_endian'} Do all unformatted I/O in big_endian mode.
  605. @item @code{'little_endian;native:10-20,25'} Do all unformatted I/O
  606. in little_endian mode, except for units 10 to 20 and 25, which are in
  607. native format.
  608. @item @code{'10-20'} Units 10 to 20 are big-endian, the rest is native.
  609. @end itemize
  610. Setting the environment variables should be done on the command
  611. line or via the @command{export}
  612. command for @command{sh}-compatible shells and via @command{setenv}
  613. for @command{csh}-compatible shells.
  614. Example for @command{sh}:
  615. @smallexample
  616. $ gfortran foo.f90
  617. $ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
  618. @end smallexample
  619. Example code for @command{csh}:
  620. @smallexample
  621. % gfortran foo.f90
  622. % setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
  623. % ./a.out
  624. @end smallexample
  625. Using anything but the native representation for unformatted data
  626. carries a significant speed overhead. If speed in this area matters
  627. to you, it is best if you use this only for data that needs to be
  628. portable.
  629. @xref{CONVERT specifier}, for an alternative way to specify the
  630. data representation for unformatted files. @xref{Runtime Options}, for
  631. setting a default data representation for the whole program. The
  632. @code{CONVERT} specifier overrides the @option{-fconvert} compile options.
  633. @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
  634. environment variable will override the CONVERT specifier in the
  635. open statement}. This is to give control over data formats to
  636. users who do not have the source code of their program available.
  637. @node GFORTRAN_ERROR_BACKTRACE
  638. @section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
  639. If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to @samp{y},
  640. @samp{Y} or @samp{1} (only the first letter is relevant) then a
  641. backtrace is printed when a serious run-time error occurs. To disable
  642. the backtracing, set the variable to @samp{n}, @samp{N}, @samp{0}.
  643. Default is to print a backtrace unless the @option{-fno-backtrace}
  644. compile option was used.
  645. @c =====================================================================
  646. @c PART II: LANGUAGE REFERENCE
  647. @c =====================================================================
  648. @tex
  649. \part{II}{Language Reference}
  650. @end tex
  651. @c ---------------------------------------------------------------------
  652. @c Fortran 2003 and 2008 Status
  653. @c ---------------------------------------------------------------------
  654. @node Fortran 2003 and 2008 status
  655. @chapter Fortran 2003 and 2008 Status
  656. @menu
  657. * Fortran 2003 status::
  658. * Fortran 2008 status::
  659. * TS 29113 status::
  660. @end menu
  661. @node Fortran 2003 status
  662. @section Fortran 2003 status
  663. GNU Fortran supports several Fortran 2003 features; an incomplete
  664. list can be found below. See also the
  665. @uref{https://gcc.gnu.org/wiki/Fortran2003, wiki page} about Fortran 2003.
  666. @itemize
  667. @item Procedure pointers including procedure-pointer components with
  668. @code{PASS} attribute.
  669. @item Procedures which are bound to a derived type (type-bound procedures)
  670. including @code{PASS}, @code{PROCEDURE} and @code{GENERIC}, and
  671. operators bound to a type.
  672. @item Abstract interfaces and type extension with the possibility to
  673. override type-bound procedures or to have deferred binding.
  674. @item Polymorphic entities (``@code{CLASS}'') for derived types and unlimited
  675. polymorphism (``@code{CLASS(*)}'') -- including @code{SAME_TYPE_AS},
  676. @code{EXTENDS_TYPE_OF} and @code{SELECT TYPE} for scalars and arrays and
  677. finalization.
  678. @item Generic interface names, which have the same name as derived types,
  679. are now supported. This allows one to write constructor functions. Note
  680. that Fortran does not support static constructor functions. For static
  681. variables, only default initialization or structure-constructor
  682. initialization are available.
  683. @item The @code{ASSOCIATE} construct.
  684. @item Interoperability with C including enumerations,
  685. @item In structure constructors the components with default values may be
  686. omitted.
  687. @item Extensions to the @code{ALLOCATE} statement, allowing for a
  688. type-specification with type parameter and for allocation and initialization
  689. from a @code{SOURCE=} expression; @code{ALLOCATE} and @code{DEALLOCATE}
  690. optionally return an error message string via @code{ERRMSG=}.
  691. @item Reallocation on assignment: If an intrinsic assignment is
  692. used, an allocatable variable on the left-hand side is automatically allocated
  693. (if unallocated) or reallocated (if the shape is different). Currently, scalar
  694. deferred character length left-hand sides are correctly handled but arrays
  695. are not yet fully implemented.
  696. @item Deferred-length character variables and scalar deferred-length character
  697. components of derived types are supported. (Note that array-valued compoents
  698. are not yet implemented.)
  699. @item Transferring of allocations via @code{MOVE_ALLOC}.
  700. @item The @code{PRIVATE} and @code{PUBLIC} attributes may be given individually
  701. to derived-type components.
  702. @item In pointer assignments, the lower bound may be specified and
  703. the remapping of elements is supported.
  704. @item For pointers an @code{INTENT} may be specified which affect the
  705. association status not the value of the pointer target.
  706. @item Intrinsics @code{command_argument_count}, @code{get_command},
  707. @code{get_command_argument}, and @code{get_environment_variable}.
  708. @item Support for Unicode characters (ISO 10646) and UTF-8, including
  709. the @code{SELECTED_CHAR_KIND} and @code{NEW_LINE} intrinsic functions.
  710. @item Support for binary, octal and hexadecimal (BOZ) constants in the
  711. intrinsic functions @code{INT}, @code{REAL}, @code{CMPLX} and @code{DBLE}.
  712. @item Support for namelist variables with allocatable and pointer
  713. attribute and nonconstant length type parameter.
  714. @item
  715. @cindex array, constructors
  716. @cindex @code{[...]}
  717. Array constructors using square brackets. That is, @code{[...]} rather
  718. than @code{(/.../)}. Type-specification for array constructors like
  719. @code{(/ some-type :: ... /)}.
  720. @item Extensions to the specification and initialization expressions,
  721. including the support for intrinsics with real and complex arguments.
  722. @item Support for the asynchronous input/output syntax; however, the
  723. data transfer is currently always synchronously performed.
  724. @item
  725. @cindex @code{FLUSH} statement
  726. @cindex statement, @code{FLUSH}
  727. @code{FLUSH} statement.
  728. @item
  729. @cindex @code{IOMSG=} specifier
  730. @code{IOMSG=} specifier for I/O statements.
  731. @item
  732. @cindex @code{ENUM} statement
  733. @cindex @code{ENUMERATOR} statement
  734. @cindex statement, @code{ENUM}
  735. @cindex statement, @code{ENUMERATOR}
  736. @opindex @code{fshort-enums}
  737. Support for the declaration of enumeration constants via the
  738. @code{ENUM} and @code{ENUMERATOR} statements. Interoperability with
  739. @command{gcc} is guaranteed also for the case where the
  740. @command{-fshort-enums} command line option is given.
  741. @item
  742. @cindex TR 15581
  743. TR 15581:
  744. @itemize
  745. @item
  746. @cindex @code{ALLOCATABLE} dummy arguments
  747. @code{ALLOCATABLE} dummy arguments.
  748. @item
  749. @cindex @code{ALLOCATABLE} function results
  750. @code{ALLOCATABLE} function results
  751. @item
  752. @cindex @code{ALLOCATABLE} components of derived types
  753. @code{ALLOCATABLE} components of derived types
  754. @end itemize
  755. @item
  756. @cindex @code{STREAM} I/O
  757. @cindex @code{ACCESS='STREAM'} I/O
  758. The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
  759. allowing I/O without any record structure.
  760. @item
  761. Namelist input/output for internal files.
  762. @item Minor I/O features: Rounding during formatted output, using of
  763. a decimal comma instead of a decimal point, setting whether a plus sign
  764. should appear for positive numbers. On systems where @code{strtod} honours
  765. the rounding mode, the rounding mode is also supported for input.
  766. @item
  767. @cindex @code{PROTECTED} statement
  768. @cindex statement, @code{PROTECTED}
  769. The @code{PROTECTED} statement and attribute.
  770. @item
  771. @cindex @code{VALUE} statement
  772. @cindex statement, @code{VALUE}
  773. The @code{VALUE} statement and attribute.
  774. @item
  775. @cindex @code{VOLATILE} statement
  776. @cindex statement, @code{VOLATILE}
  777. The @code{VOLATILE} statement and attribute.
  778. @item
  779. @cindex @code{IMPORT} statement
  780. @cindex statement, @code{IMPORT}
  781. The @code{IMPORT} statement, allowing to import
  782. host-associated derived types.
  783. @item The intrinsic modules @code{ISO_FORTRAN_ENVIRONMENT} is supported,
  784. which contains parameters of the I/O units, storage sizes. Additionally,
  785. procedures for C interoperability are available in the @code{ISO_C_BINDING}
  786. module.
  787. @item
  788. @cindex @code{USE, INTRINSIC} statement
  789. @cindex statement, @code{USE, INTRINSIC}
  790. @cindex @code{ISO_FORTRAN_ENV} statement
  791. @cindex statement, @code{ISO_FORTRAN_ENV}
  792. @code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
  793. attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
  794. @code{ISO_C_BINDING}, @code{OMP_LIB} and @code{OMP_LIB_KINDS},
  795. and @code{OPENACC}.
  796. @item
  797. Renaming of operators in the @code{USE} statement.
  798. @end itemize
  799. @node Fortran 2008 status
  800. @section Fortran 2008 status
  801. The latest version of the Fortran standard is ISO/IEC 1539-1:2010, informally
  802. known as Fortran 2008. The official version is available from International
  803. Organization for Standardization (ISO) or its national member organizations.
  804. The the final draft (FDIS) can be downloaded free of charge from
  805. @url{http://www.nag.co.uk/@/sc22wg5/@/links.html}. Fortran is developed by the
  806. Working Group 5 of Sub-Committee 22 of the Joint Technical Committee 1 of the
  807. International Organization for Standardization and the International
  808. Electrotechnical Commission (IEC). This group is known as
  809. @uref{http://www.nag.co.uk/sc22wg5/, WG5}.
  810. The GNU Fortran compiler supports several of the new features of Fortran 2008;
  811. the @uref{https://gcc.gnu.org/wiki/Fortran2008Status, wiki} has some information
  812. about the current Fortran 2008 implementation status. In particular, the
  813. following is implemented.
  814. @itemize
  815. @item The @option{-std=f2008} option and support for the file extensions
  816. @file{.f08} and @file{.F08}.
  817. @item The @code{OPEN} statement now supports the @code{NEWUNIT=} option,
  818. which returns a unique file unit, thus preventing inadvertent use of the
  819. same unit in different parts of the program.
  820. @item The @code{g0} format descriptor and unlimited format items.
  821. @item The mathematical intrinsics @code{ASINH}, @code{ACOSH}, @code{ATANH},
  822. @code{ERF}, @code{ERFC}, @code{GAMMA}, @code{LOG_GAMMA}, @code{BESSEL_J0},
  823. @code{BESSEL_J1}, @code{BESSEL_JN}, @code{BESSEL_Y0}, @code{BESSEL_Y1},
  824. @code{BESSEL_YN}, @code{HYPOT}, @code{NORM2}, and @code{ERFC_SCALED}.
  825. @item Using complex arguments with @code{TAN}, @code{SINH}, @code{COSH},
  826. @code{TANH}, @code{ASIN}, @code{ACOS}, and @code{ATAN} is now possible;
  827. @code{ATAN}(@var{Y},@var{X}) is now an alias for @code{ATAN2}(@var{Y},@var{X}).
  828. @item Support of the @code{PARITY} intrinsic functions.
  829. @item The following bit intrinsics: @code{LEADZ} and @code{TRAILZ} for
  830. counting the number of leading and trailing zero bits, @code{POPCNT} and
  831. @code{POPPAR} for counting the number of one bits and returning the parity;
  832. @code{BGE}, @code{BGT}, @code{BLE}, and @code{BLT} for bitwise comparisons;
  833. @code{DSHIFTL} and @code{DSHIFTR} for combined left and right shifts,
  834. @code{MASKL} and @code{MASKR} for simple left and right justified masks,
  835. @code{MERGE_BITS} for a bitwise merge using a mask, @code{SHIFTA},
  836. @code{SHIFTL} and @code{SHIFTR} for shift operations, and the
  837. transformational bit intrinsics @code{IALL}, @code{IANY} and @code{IPARITY}.
  838. @item Support of the @code{EXECUTE_COMMAND_LINE} intrinsic subroutine.
  839. @item Support for the @code{STORAGE_SIZE} intrinsic inquiry function.
  840. @item The @code{INT@{8,16,32@}} and @code{REAL@{32,64,128@}} kind type
  841. parameters and the array-valued named constants @code{INTEGER_KINDS},
  842. @code{LOGICAL_KINDS}, @code{REAL_KINDS} and @code{CHARACTER_KINDS} of
  843. the intrinsic module @code{ISO_FORTRAN_ENV}.
  844. @item The module procedures @code{C_SIZEOF} of the intrinsic module
  845. @code{ISO_C_BINDINGS} and @code{COMPILER_VERSION} and @code{COMPILER_OPTIONS}
  846. of @code{ISO_FORTRAN_ENV}.
  847. @item Coarray support for serial programs with @option{-fcoarray=single} flag
  848. and experimental support for multiple images with the @option{-fcoarray=lib}
  849. flag.
  850. @item The @code{DO CONCURRENT} construct is supported.
  851. @item The @code{BLOCK} construct is supported.
  852. @item The @code{STOP} and the new @code{ERROR STOP} statements now
  853. support all constant expressions. Both show the signals which were signaling
  854. at termination.
  855. @item Support for the @code{CONTIGUOUS} attribute.
  856. @item Support for @code{ALLOCATE} with @code{MOLD}.
  857. @item Support for the @code{IMPURE} attribute for procedures, which
  858. allows for @code{ELEMENTAL} procedures without the restrictions of
  859. @code{PURE}.
  860. @item Null pointers (including @code{NULL()}) and not-allocated variables
  861. can be used as actual argument to optional non-pointer, non-allocatable
  862. dummy arguments, denoting an absent argument.
  863. @item Non-pointer variables with @code{TARGET} attribute can be used as
  864. actual argument to @code{POINTER} dummies with @code{INTENT(IN)}.
  865. @item Pointers including procedure pointers and those in a derived
  866. type (pointer components) can now be initialized by a target instead
  867. of only by @code{NULL}.
  868. @item The @code{EXIT} statement (with construct-name) can be now be
  869. used to leave not only the @code{DO} but also the @code{ASSOCIATE},
  870. @code{BLOCK}, @code{IF}, @code{SELECT CASE} and @code{SELECT TYPE}
  871. constructs.
  872. @item Internal procedures can now be used as actual argument.
  873. @item Minor features: obsolesce diagnostics for @code{ENTRY} with
  874. @option{-std=f2008}; a line may start with a semicolon; for internal
  875. and module procedures @code{END} can be used instead of
  876. @code{END SUBROUTINE} and @code{END FUNCTION}; @code{SELECTED_REAL_KIND}
  877. now also takes a @code{RADIX} argument; intrinsic types are supported
  878. for @code{TYPE}(@var{intrinsic-type-spec}); multiple type-bound procedures
  879. can be declared in a single @code{PROCEDURE} statement; implied-shape
  880. arrays are supported for named constants (@code{PARAMETER}).
  881. @end itemize
  882. @node TS 29113 status
  883. @section Technical Specification 29113 Status
  884. GNU Fortran supports some of the new features of the Technical
  885. Specification (TS) 29113 on Further Interoperability of Fortran with C.
  886. The @uref{https://gcc.gnu.org/wiki/TS29113Status, wiki} has some information
  887. about the current TS 29113 implementation status. In particular, the
  888. following is implemented.
  889. See also @ref{Further Interoperability of Fortran with C}.
  890. @itemize
  891. @item The @option{-std=f2008ts} option.
  892. @item The @code{OPTIONAL} attribute is allowed for dummy arguments
  893. of @code{BIND(C) procedures.}
  894. @item The @code{RANK} intrinsic is supported.
  895. @item GNU Fortran's implementation for variables with @code{ASYNCHRONOUS}
  896. attribute is compatible with TS 29113.
  897. @item Assumed types (@code{TYPE(*)}.
  898. @item Assumed-rank (@code{DIMENSION(..)}). However, the array descriptor
  899. of the TS is not yet supported.
  900. @end itemize
  901. @c ---------------------------------------------------------------------
  902. @c Compiler Characteristics
  903. @c ---------------------------------------------------------------------
  904. @node Compiler Characteristics
  905. @chapter Compiler Characteristics
  906. This chapter describes certain characteristics of the GNU Fortran
  907. compiler, that are not specified by the Fortran standard, but which
  908. might in some way or another become visible to the programmer.
  909. @menu
  910. * KIND Type Parameters::
  911. * Internal representation of LOGICAL variables::
  912. * Thread-safety of the runtime library::
  913. * Data consistency and durability::
  914. * Files opened without an explicit ACTION= specifier::
  915. @end menu
  916. @node KIND Type Parameters
  917. @section KIND Type Parameters
  918. @cindex kind
  919. The @code{KIND} type parameters supported by GNU Fortran for the primitive
  920. data types are:
  921. @table @code
  922. @item INTEGER
  923. 1, 2, 4, 8*, 16*, default: 4**
  924. @item LOGICAL
  925. 1, 2, 4, 8*, 16*, default: 4**
  926. @item REAL
  927. 4, 8, 10*, 16*, default: 4***
  928. @item COMPLEX
  929. 4, 8, 10*, 16*, default: 4***
  930. @item DOUBLE PRECISION
  931. 4, 8, 10*, 16*, default: 8***
  932. @item CHARACTER
  933. 1, 4, default: 1
  934. @end table
  935. @noindent
  936. * not available on all systems @*
  937. ** unless @option{-fdefault-integer-8} is used @*
  938. *** unless @option{-fdefault-real-8} is used (see @ref{Fortran Dialect Options})
  939. @noindent
  940. The @code{KIND} value matches the storage size in bytes, except for
  941. @code{COMPLEX} where the storage size is twice as much (or both real and
  942. imaginary part are a real value of the given size). It is recommended to use
  943. the @ref{SELECTED_CHAR_KIND}, @ref{SELECTED_INT_KIND} and
  944. @ref{SELECTED_REAL_KIND} intrinsics or the @code{INT8}, @code{INT16},
  945. @code{INT32}, @code{INT64}, @code{REAL32}, @code{REAL64}, and @code{REAL128}
  946. parameters of the @code{ISO_FORTRAN_ENV} module instead of the concrete values.
  947. The available kind parameters can be found in the constant arrays
  948. @code{CHARACTER_KINDS}, @code{INTEGER_KINDS}, @code{LOGICAL_KINDS} and
  949. @code{REAL_KINDS} in the @ref{ISO_FORTRAN_ENV} module. For C interoperability,
  950. the kind parameters of the @ref{ISO_C_BINDING} module should be used.
  951. @node Internal representation of LOGICAL variables
  952. @section Internal representation of LOGICAL variables
  953. @cindex logical, variable representation
  954. The Fortran standard does not specify how variables of @code{LOGICAL}
  955. type are represented, beyond requiring that @code{LOGICAL} variables
  956. of default kind have the same storage size as default @code{INTEGER}
  957. and @code{REAL} variables. The GNU Fortran internal representation is
  958. as follows.
  959. A @code{LOGICAL(KIND=N)} variable is represented as an
  960. @code{INTEGER(KIND=N)} variable, however, with only two permissible
  961. values: @code{1} for @code{.TRUE.} and @code{0} for
  962. @code{.FALSE.}. Any other integer value results in undefined behavior.
  963. See also @ref{Argument passing conventions} and @ref{Interoperability with C}.
  964. @node Thread-safety of the runtime library
  965. @section Thread-safety of the runtime library
  966. @cindex thread-safety, threads
  967. GNU Fortran can be used in programs with multiple threads, e.g.@: by
  968. using OpenMP, by calling OS thread handling functions via the
  969. @code{ISO_C_BINDING} facility, or by GNU Fortran compiled library code
  970. being called from a multi-threaded program.
  971. The GNU Fortran runtime library, (@code{libgfortran}), supports being
  972. called concurrently from multiple threads with the following
  973. exceptions.
  974. During library initialization, the C @code{getenv} function is used,
  975. which need not be thread-safe. Similarly, the @code{getenv}
  976. function is used to implement the @code{GET_ENVIRONMENT_VARIABLE} and
  977. @code{GETENV} intrinsics. It is the responsibility of the user to
  978. ensure that the environment is not being updated concurrently when any
  979. of these actions are taking place.
  980. The @code{EXECUTE_COMMAND_LINE} and @code{SYSTEM} intrinsics are
  981. implemented with the @code{system} function, which need not be
  982. thread-safe. It is the responsibility of the user to ensure that
  983. @code{system} is not called concurrently.
  984. For platforms not supporting thread-safe POSIX functions, further
  985. functionality might not be thread-safe. For details, please consult
  986. the documentation for your operating system.
  987. The GNU Fortran runtime library uses various C library functions that
  988. depend on the locale, such as @code{strtod} and @code{snprintf}. In
  989. order to work correctly in locale-aware programs that set the locale
  990. using @code{setlocale}, the locale is reset to the default ``C''
  991. locale while executing a formatted @code{READ} or @code{WRITE}
  992. statement. On targets supporting the POSIX 2008 per-thread locale
  993. functions (e.g. @code{newlocale}, @code{uselocale},
  994. @code{freelocale}), these are used and thus the global locale set
  995. using @code{setlocale} or the per-thread locales in other threads are
  996. not affected. However, on targets lacking this functionality, the
  997. global LC_NUMERIC locale is set to ``C'' during the formatted I/O.
  998. Thus, on such targets it's not safe to call @code{setlocale}
  999. concurrently from another thread while a Fortran formatted I/O
  1000. operation is in progress. Also, other threads doing something
  1001. dependent on the LC_NUMERIC locale might not work correctly if a
  1002. formatted I/O operation is in progress in another thread.
  1003. @node Data consistency and durability
  1004. @section Data consistency and durability
  1005. @cindex consistency, durability
  1006. This section contains a brief overview of data and metadata
  1007. consistency and durability issues when doing I/O.
  1008. With respect to durability, GNU Fortran makes no effort to ensure that
  1009. data is committed to stable storage. If this is required, the GNU
  1010. Fortran programmer can use the intrinsic @code{FNUM} to retrieve the
  1011. low level file descriptor corresponding to an open Fortran unit. Then,
  1012. using e.g. the @code{ISO_C_BINDING} feature, one can call the
  1013. underlying system call to flush dirty data to stable storage, such as
  1014. @code{fsync} on POSIX, @code{_commit} on MingW, or @code{fcntl(fd,
  1015. F_FULLSYNC, 0)} on Mac OS X. The following example shows how to call
  1016. fsync:
  1017. @smallexample
  1018. ! Declare the interface for POSIX fsync function
  1019. interface
  1020. function fsync (fd) bind(c,name="fsync")
  1021. use iso_c_binding, only: c_int
  1022. integer(c_int), value :: fd
  1023. integer(c_int) :: fsync
  1024. end function fsync
  1025. end interface
  1026. ! Variable declaration
  1027. integer :: ret
  1028. ! Opening unit 10
  1029. open (10,file="foo")
  1030. ! ...
  1031. ! Perform I/O on unit 10
  1032. ! ...
  1033. ! Flush and sync
  1034. flush(10)
  1035. ret = fsync(fnum(10))
  1036. ! Handle possible error
  1037. if (ret /= 0) stop "Error calling FSYNC"
  1038. @end smallexample
  1039. With respect to consistency, for regular files GNU Fortran uses
  1040. buffered I/O in order to improve performance. This buffer is flushed
  1041. automatically when full and in some other situations, e.g. when
  1042. closing a unit. It can also be explicitly flushed with the
  1043. @code{FLUSH} statement. Also, the buffering can be turned off with the
  1044. @code{GFORTRAN_UNBUFFERED_ALL} and
  1045. @code{GFORTRAN_UNBUFFERED_PRECONNECTED} environment variables. Special
  1046. files, such as terminals and pipes, are always unbuffered. Sometimes,
  1047. however, further things may need to be done in order to allow other
  1048. processes to see data that GNU Fortran has written, as follows.
  1049. The Windows platform supports a relaxed metadata consistency model,
  1050. where file metadata is written to the directory lazily. This means
  1051. that, for instance, the @code{dir} command can show a stale size for a
  1052. file. One can force a directory metadata update by closing the unit,
  1053. or by calling @code{_commit} on the file descriptor. Note, though,
  1054. that @code{_commit} will force all dirty data to stable storage, which
  1055. is often a very slow operation.
  1056. The Network File System (NFS) implements a relaxed consistency model
  1057. called open-to-close consistency. Closing a file forces dirty data and
  1058. metadata to be flushed to the server, and opening a file forces the
  1059. client to contact the server in order to revalidate cached
  1060. data. @code{fsync} will also force a flush of dirty data and metadata
  1061. to the server. Similar to @code{open} and @code{close}, acquiring and
  1062. releasing @code{fcntl} file locks, if the server supports them, will
  1063. also force cache validation and flushing dirty data and metadata.
  1064. @node Files opened without an explicit ACTION= specifier
  1065. @section Files opened without an explicit ACTION= specifier
  1066. @cindex open, action
  1067. The Fortran standard says that if an @code{OPEN} statement is executed
  1068. without an explicit @code{ACTION=} specifier, the default value is
  1069. processor dependent. GNU Fortran behaves as follows:
  1070. @enumerate
  1071. @item Attempt to open the file with @code{ACTION='READWRITE'}
  1072. @item If that fails, try to open with @code{ACTION='READ'}
  1073. @item If that fails, try to open with @code{ACTION='WRITE'}
  1074. @item If that fails, generate an error
  1075. @end enumerate
  1076. @c ---------------------------------------------------------------------
  1077. @c Extensions
  1078. @c ---------------------------------------------------------------------
  1079. @c Maybe this chapter should be merged with the 'Standards' section,
  1080. @c whenever that is written :-)
  1081. @node Extensions
  1082. @chapter Extensions
  1083. @cindex extensions
  1084. The two sections below detail the extensions to standard Fortran that are
  1085. implemented in GNU Fortran, as well as some of the popular or
  1086. historically important extensions that are not (or not yet) implemented.
  1087. For the latter case, we explain the alternatives available to GNU Fortran
  1088. users, including replacement by standard-conforming code or GNU
  1089. extensions.
  1090. @menu
  1091. * Extensions implemented in GNU Fortran::
  1092. * Extensions not implemented in GNU Fortran::
  1093. @end menu
  1094. @node Extensions implemented in GNU Fortran
  1095. @section Extensions implemented in GNU Fortran
  1096. @cindex extensions, implemented
  1097. GNU Fortran implements a number of extensions over standard
  1098. Fortran. This chapter contains information on their syntax and
  1099. meaning. There are currently two categories of GNU Fortran
  1100. extensions, those that provide functionality beyond that provided
  1101. by any standard, and those that are supported by GNU Fortran
  1102. purely for backward compatibility with legacy compilers. By default,
  1103. @option{-std=gnu} allows the compiler to accept both types of
  1104. extensions, but to warn about the use of the latter. Specifying
  1105. either @option{-std=f95}, @option{-std=f2003} or @option{-std=f2008}
  1106. disables both types of extensions, and @option{-std=legacy} allows both
  1107. without warning.
  1108. @menu
  1109. * Old-style kind specifications::
  1110. * Old-style variable initialization::
  1111. * Extensions to namelist::
  1112. * X format descriptor without count field::
  1113. * Commas in FORMAT specifications::
  1114. * Missing period in FORMAT specifications::
  1115. * I/O item lists::
  1116. * @code{Q} exponent-letter::
  1117. * BOZ literal constants::
  1118. * Real array indices::
  1119. * Unary operators::
  1120. * Implicitly convert LOGICAL and INTEGER values::
  1121. * Hollerith constants support::
  1122. * Cray pointers::
  1123. * CONVERT specifier::
  1124. * OpenMP::
  1125. * OpenACC::
  1126. * Argument list functions::
  1127. * Read/Write after EOF marker::
  1128. @end menu
  1129. @node Old-style kind specifications
  1130. @subsection Old-style kind specifications
  1131. @cindex kind, old-style
  1132. GNU Fortran allows old-style kind specifications in declarations. These
  1133. look like:
  1134. @smallexample
  1135. TYPESPEC*size x,y,z
  1136. @end smallexample
  1137. @noindent
  1138. where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
  1139. etc.), and where @code{size} is a byte count corresponding to the
  1140. storage size of a valid kind for that type. (For @code{COMPLEX}
  1141. variables, @code{size} is the total size of the real and imaginary
  1142. parts.) The statement then declares @code{x}, @code{y} and @code{z} to
  1143. be of type @code{TYPESPEC} with the appropriate kind. This is
  1144. equivalent to the standard-conforming declaration
  1145. @smallexample
  1146. TYPESPEC(k) x,y,z
  1147. @end smallexample
  1148. @noindent
  1149. where @code{k} is the kind parameter suitable for the intended precision. As
  1150. kind parameters are implementation-dependent, use the @code{KIND},
  1151. @code{SELECTED_INT_KIND} and @code{SELECTED_REAL_KIND} intrinsics to retrieve
  1152. the correct value, for instance @code{REAL*8 x} can be replaced by:
  1153. @smallexample
  1154. INTEGER, PARAMETER :: dbl = KIND(1.0d0)
  1155. REAL(KIND=dbl) :: x
  1156. @end smallexample
  1157. @node Old-style variable initialization
  1158. @subsection Old-style variable initialization
  1159. GNU Fortran allows old-style initialization of variables of the
  1160. form:
  1161. @smallexample
  1162. INTEGER i/1/,j/2/
  1163. REAL x(2,2) /3*0.,1./
  1164. @end smallexample
  1165. The syntax for the initializers is as for the @code{DATA} statement, but
  1166. unlike in a @code{DATA} statement, an initializer only applies to the
  1167. variable immediately preceding the initialization. In other words,
  1168. something like @code{INTEGER I,J/2,3/} is not valid. This style of
  1169. initialization is only allowed in declarations without double colons
  1170. (@code{::}); the double colons were introduced in Fortran 90, which also
  1171. introduced a standard syntax for initializing variables in type
  1172. declarations.
  1173. Examples of standard-conforming code equivalent to the above example
  1174. are:
  1175. @smallexample
  1176. ! Fortran 90
  1177. INTEGER :: i = 1, j = 2
  1178. REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
  1179. ! Fortran 77
  1180. INTEGER i, j
  1181. REAL x(2,2)
  1182. DATA i/1/, j/2/, x/3*0.,1./
  1183. @end smallexample
  1184. Note that variables which are explicitly initialized in declarations
  1185. or in @code{DATA} statements automatically acquire the @code{SAVE}
  1186. attribute.
  1187. @node Extensions to namelist
  1188. @subsection Extensions to namelist
  1189. @cindex Namelist
  1190. GNU Fortran fully supports the Fortran 95 standard for namelist I/O
  1191. including array qualifiers, substrings and fully qualified derived types.
  1192. The output from a namelist write is compatible with namelist read. The
  1193. output has all names in upper case and indentation to column 1 after the
  1194. namelist name. Two extensions are permitted:
  1195. Old-style use of @samp{$} instead of @samp{&}
  1196. @smallexample
  1197. $MYNML
  1198. X(:)%Y(2) = 1.0 2.0 3.0
  1199. CH(1:4) = "abcd"
  1200. $END
  1201. @end smallexample
  1202. It should be noted that the default terminator is @samp{/} rather than
  1203. @samp{&END}.
  1204. Querying of the namelist when inputting from stdin. After at least
  1205. one space, entering @samp{?} sends to stdout the namelist name and the names of
  1206. the variables in the namelist:
  1207. @smallexample
  1208. ?
  1209. &mynml
  1210. x
  1211. x%y
  1212. ch
  1213. &end
  1214. @end smallexample
  1215. Entering @samp{=?} outputs the namelist to stdout, as if
  1216. @code{WRITE(*,NML = mynml)} had been called:
  1217. @smallexample
  1218. =?
  1219. &MYNML
  1220. X(1)%Y= 0.000000 , 1.000000 , 0.000000 ,
  1221. X(2)%Y= 0.000000 , 2.000000 , 0.000000 ,
  1222. X(3)%Y= 0.000000 , 3.000000 , 0.000000 ,
  1223. CH=abcd, /
  1224. @end smallexample
  1225. To aid this dialog, when input is from stdin, errors send their
  1226. messages to stderr and execution continues, even if @code{IOSTAT} is set.
  1227. @code{PRINT} namelist is permitted. This causes an error if
  1228. @option{-std=f95} is used.
  1229. @smallexample
  1230. PROGRAM test_print
  1231. REAL, dimension (4) :: x = (/1.0, 2.0, 3.0, 4.0/)
  1232. NAMELIST /mynml/ x
  1233. PRINT mynml
  1234. END PROGRAM test_print
  1235. @end smallexample
  1236. Expanded namelist reads are permitted. This causes an error if
  1237. @option{-std=f95} is used. In the following example, the first element
  1238. of the array will be given the value 0.00 and the two succeeding
  1239. elements will be given the values 1.00 and 2.00.
  1240. @smallexample
  1241. &MYNML
  1242. X(1,1) = 0.00 , 1.00 , 2.00
  1243. /
  1244. @end smallexample
  1245. When writing a namelist, if no @code{DELIM=} is specified, by default a
  1246. double quote is used to delimit character strings. If -std=F95, F2003,
  1247. or F2008, etc, the delim status is set to 'none'. Defaulting to
  1248. quotes ensures that namelists with character strings can be subsequently
  1249. read back in accurately.
  1250. @node X format descriptor without count field
  1251. @subsection @code{X} format descriptor without count field
  1252. To support legacy codes, GNU Fortran permits the count field of the
  1253. @code{X} edit descriptor in @code{FORMAT} statements to be omitted.
  1254. When omitted, the count is implicitly assumed to be one.
  1255. @smallexample
  1256. PRINT 10, 2, 3
  1257. 10 FORMAT (I1, X, I1)
  1258. @end smallexample
  1259. @node Commas in FORMAT specifications
  1260. @subsection Commas in @code{FORMAT} specifications
  1261. To support legacy codes, GNU Fortran allows the comma separator
  1262. to be omitted immediately before and after character string edit
  1263. descriptors in @code{FORMAT} statements.
  1264. @smallexample
  1265. PRINT 10, 2, 3
  1266. 10 FORMAT ('FOO='I1' BAR='I2)
  1267. @end smallexample
  1268. @node Missing period in FORMAT specifications
  1269. @subsection Missing period in @code{FORMAT} specifications
  1270. To support legacy codes, GNU Fortran allows missing periods in format
  1271. specifications if and only if @option{-std=legacy} is given on the
  1272. command line. This is considered non-conforming code and is
  1273. discouraged.
  1274. @smallexample
  1275. REAL :: value
  1276. READ(*,10) value
  1277. 10 FORMAT ('F4')
  1278. @end smallexample
  1279. @node I/O item lists
  1280. @subsection I/O item lists
  1281. @cindex I/O item lists
  1282. To support legacy codes, GNU Fortran allows the input item list
  1283. of the @code{READ} statement, and the output item lists of the
  1284. @code{WRITE} and @code{PRINT} statements, to start with a comma.
  1285. @node @code{Q} exponent-letter
  1286. @subsection @code{Q} exponent-letter
  1287. @cindex @code{Q} exponent-letter
  1288. GNU Fortran accepts real literal constants with an exponent-letter
  1289. of @code{Q}, for example, @code{1.23Q45}. The constant is interpreted
  1290. as a @code{REAL(16)} entity on targets that support this type. If
  1291. the target does not support @code{REAL(16)} but has a @code{REAL(10)}
  1292. type, then the real-literal-constant will be interpreted as a
  1293. @code{REAL(10)} entity. In the absence of @code{REAL(16)} and
  1294. @code{REAL(10)}, an error will occur.
  1295. @node BOZ literal constants
  1296. @subsection BOZ literal constants
  1297. @cindex BOZ literal constants
  1298. Besides decimal constants, Fortran also supports binary (@code{b}),
  1299. octal (@code{o}) and hexadecimal (@code{z}) integer constants. The
  1300. syntax is: @samp{prefix quote digits quote}, were the prefix is
  1301. either @code{b}, @code{o} or @code{z}, quote is either @code{'} or
  1302. @code{"} and the digits are for binary @code{0} or @code{1}, for
  1303. octal between @code{0} and @code{7}, and for hexadecimal between
  1304. @code{0} and @code{F}. (Example: @code{b'01011101'}.)
  1305. Up to Fortran 95, BOZ literals were only allowed to initialize
  1306. integer variables in DATA statements. Since Fortran 2003 BOZ literals
  1307. are also allowed as argument of @code{REAL}, @code{DBLE}, @code{INT}
  1308. and @code{CMPLX}; the result is the same as if the integer BOZ
  1309. literal had been converted by @code{TRANSFER} to, respectively,
  1310. @code{real}, @code{double precision}, @code{integer} or @code{complex}.
  1311. As GNU Fortran extension the intrinsic procedures @code{FLOAT},
  1312. @code{DFLOAT}, @code{COMPLEX} and @code{DCMPLX} are treated alike.
  1313. As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
  1314. be specified using the @code{X} prefix, in addition to the standard
  1315. @code{Z} prefix. The BOZ literal can also be specified by adding a
  1316. suffix to the string, for example, @code{Z'ABC'} and @code{'ABC'Z} are
  1317. equivalent.
  1318. Furthermore, GNU Fortran allows using BOZ literal constants outside
  1319. DATA statements and the four intrinsic functions allowed by Fortran 2003.
  1320. In DATA statements, in direct assignments, where the right-hand side
  1321. only contains a BOZ literal constant, and for old-style initializers of
  1322. the form @code{integer i /o'0173'/}, the constant is transferred
  1323. as if @code{TRANSFER} had been used; for @code{COMPLEX} numbers, only
  1324. the real part is initialized unless @code{CMPLX} is used. In all other
  1325. cases, the BOZ literal constant is converted to an @code{INTEGER} value with
  1326. the largest decimal representation. This value is then converted
  1327. numerically to the type and kind of the variable in question.
  1328. (For instance, @code{real :: r = b'0000001' + 1} initializes @code{r}
  1329. with @code{2.0}.) As different compilers implement the extension
  1330. differently, one should be careful when doing bitwise initialization
  1331. of non-integer variables.
  1332. Note that initializing an @code{INTEGER} variable with a statement such
  1333. as @code{DATA i/Z'FFFFFFFF'/} will give an integer overflow error rather
  1334. than the desired result of @math{-1} when @code{i} is a 32-bit integer
  1335. on a system that supports 64-bit integers. The @samp{-fno-range-check}
  1336. option can be used as a workaround for legacy code that initializes
  1337. integers in this manner.
  1338. @node Real array indices
  1339. @subsection Real array indices
  1340. @cindex array, indices of type real
  1341. As an extension, GNU Fortran allows the use of @code{REAL} expressions
  1342. or variables as array indices.
  1343. @node Unary operators
  1344. @subsection Unary operators
  1345. @cindex operators, unary
  1346. As an extension, GNU Fortran allows unary plus and unary minus operators
  1347. to appear as the second operand of binary arithmetic operators without
  1348. the need for parenthesis.
  1349. @smallexample
  1350. X = Y * -Z
  1351. @end smallexample
  1352. @node Implicitly convert LOGICAL and INTEGER values
  1353. @subsection Implicitly convert @code{LOGICAL} and @code{INTEGER} values
  1354. @cindex conversion, to integer
  1355. @cindex conversion, to logical
  1356. As an extension for backwards compatibility with other compilers, GNU
  1357. Fortran allows the implicit conversion of @code{LOGICAL} values to
  1358. @code{INTEGER} values and vice versa. When converting from a
  1359. @code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
  1360. zero, and @code{.TRUE.} is interpreted as one. When converting from
  1361. @code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
  1362. @code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
  1363. @smallexample
  1364. LOGICAL :: l
  1365. l = 1
  1366. @end smallexample
  1367. @smallexample
  1368. INTEGER :: i
  1369. i = .TRUE.
  1370. @end smallexample
  1371. However, there is no implicit conversion of @code{INTEGER} values in
  1372. @code{if}-statements, nor of @code{LOGICAL} or @code{INTEGER} values
  1373. in I/O operations.
  1374. @node Hollerith constants support
  1375. @subsection Hollerith constants support
  1376. @cindex Hollerith constants
  1377. GNU Fortran supports Hollerith constants in assignments, function
  1378. arguments, and @code{DATA} and @code{ASSIGN} statements. A Hollerith
  1379. constant is written as a string of characters preceded by an integer
  1380. constant indicating the character count, and the letter @code{H} or
  1381. @code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
  1382. @code{REAL}, or @code{complex}) or @code{LOGICAL} variable. The
  1383. constant will be padded or truncated to fit the size of the variable in
  1384. which it is stored.
  1385. Examples of valid uses of Hollerith constants:
  1386. @smallexample
  1387. complex*16 x(2)
  1388. data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
  1389. x(1) = 16HABCDEFGHIJKLMNOP
  1390. call foo (4h abc)
  1391. @end smallexample
  1392. Invalid Hollerith constants examples:
  1393. @smallexample
  1394. integer*4 a
  1395. a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
  1396. a = 0H ! At least one character is needed.
  1397. @end smallexample
  1398. In general, Hollerith constants were used to provide a rudimentary
  1399. facility for handling character strings in early Fortran compilers,
  1400. prior to the introduction of @code{CHARACTER} variables in Fortran 77;
  1401. in those cases, the standard-compliant equivalent is to convert the
  1402. program to use proper character strings. On occasion, there may be a
  1403. case where the intent is specifically to initialize a numeric variable
  1404. with a given byte sequence. In these cases, the same result can be
  1405. obtained by using the @code{TRANSFER} statement, as in this example.
  1406. @smallexample
  1407. INTEGER(KIND=4) :: a
  1408. a = TRANSFER ("abcd", a) ! equivalent to: a = 4Habcd
  1409. @end smallexample
  1410. @node Cray pointers
  1411. @subsection Cray pointers
  1412. @cindex pointer, Cray
  1413. Cray pointers are part of a non-standard extension that provides a
  1414. C-like pointer in Fortran. This is accomplished through a pair of
  1415. variables: an integer "pointer" that holds a memory address, and a
  1416. "pointee" that is used to dereference the pointer.
  1417. Pointer/pointee pairs are declared in statements of the form:
  1418. @smallexample
  1419. pointer ( <pointer> , <pointee> )
  1420. @end smallexample
  1421. or,
  1422. @smallexample
  1423. pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
  1424. @end smallexample
  1425. The pointer is an integer that is intended to hold a memory address.
  1426. The pointee may be an array or scalar. A pointee can be an assumed
  1427. size array---that is, the last dimension may be left unspecified by
  1428. using a @code{*} in place of a value---but a pointee cannot be an
  1429. assumed shape array. No space is allocated for the pointee.
  1430. The pointee may have its type declared before or after the pointer
  1431. statement, and its array specification (if any) may be declared
  1432. before, during, or after the pointer statement. The pointer may be
  1433. declared as an integer prior to the pointer statement. However, some
  1434. machines have default integer sizes that are different than the size
  1435. of a pointer, and so the following code is not portable:
  1436. @smallexample
  1437. integer ipt
  1438. pointer (ipt, iarr)
  1439. @end smallexample
  1440. If a pointer is declared with a kind that is too small, the compiler
  1441. will issue a warning; the resulting binary will probably not work
  1442. correctly, because the memory addresses stored in the pointers may be
  1443. truncated. It is safer to omit the first line of the above example;
  1444. if explicit declaration of ipt's type is omitted, then the compiler
  1445. will ensure that ipt is an integer variable large enough to hold a
  1446. pointer.
  1447. Pointer arithmetic is valid with Cray pointers, but it is not the same
  1448. as C pointer arithmetic. Cray pointers are just ordinary integers, so
  1449. the user is responsible for determining how many bytes to add to a
  1450. pointer in order to increment it. Consider the following example:
  1451. @smallexample
  1452. real target(10)
  1453. real pointee(10)
  1454. pointer (ipt, pointee)
  1455. ipt = loc (target)
  1456. ipt = ipt + 1
  1457. @end smallexample
  1458. The last statement does not set @code{ipt} to the address of
  1459. @code{target(1)}, as it would in C pointer arithmetic. Adding @code{1}
  1460. to @code{ipt} just adds one byte to the address stored in @code{ipt}.
  1461. Any expression involving the pointee will be translated to use the
  1462. value stored in the pointer as the base address.
  1463. To get the address of elements, this extension provides an intrinsic
  1464. function @code{LOC()}. The @code{LOC()} function is equivalent to the
  1465. @code{&} operator in C, except the address is cast to an integer type:
  1466. @smallexample
  1467. real ar(10)
  1468. pointer(ipt, arpte(10))
  1469. real arpte
  1470. ipt = loc(ar) ! Makes arpte is an alias for ar
  1471. arpte(1) = 1.0 ! Sets ar(1) to 1.0
  1472. @end smallexample
  1473. The pointer can also be set by a call to the @code{MALLOC} intrinsic
  1474. (see @ref{MALLOC}).
  1475. Cray pointees often are used to alias an existing variable. For
  1476. example:
  1477. @smallexample
  1478. integer target(10)
  1479. integer iarr(10)
  1480. pointer (ipt, iarr)
  1481. ipt = loc(target)
  1482. @end smallexample
  1483. As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
  1484. @code{target}. The optimizer, however, will not detect this aliasing, so
  1485. it is unsafe to use @code{iarr} and @code{target} simultaneously. Using
  1486. a pointee in any way that violates the Fortran aliasing rules or
  1487. assumptions is illegal. It is the user's responsibility to avoid doing
  1488. this; the compiler works under the assumption that no such aliasing
  1489. occurs.
  1490. Cray pointers will work correctly when there is no aliasing (i.e., when
  1491. they are used to access a dynamically allocated block of memory), and
  1492. also in any routine where a pointee is used, but any variable with which
  1493. it shares storage is not used. Code that violates these rules may not
  1494. run as the user intends. This is not a bug in the optimizer; any code
  1495. that violates the aliasing rules is illegal. (Note that this is not
  1496. unique to GNU Fortran; any Fortran compiler that supports Cray pointers
  1497. will ``incorrectly'' optimize code with illegal aliasing.)
  1498. There are a number of restrictions on the attributes that can be applied
  1499. to Cray pointers and pointees. Pointees may not have the
  1500. @code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
  1501. @code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes. Pointers
  1502. may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
  1503. @code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes, nor
  1504. may they be function results. Pointees may not occur in more than one
  1505. pointer statement. A pointee cannot be a pointer. Pointees cannot occur
  1506. in equivalence, common, or data statements.
  1507. A Cray pointer may also point to a function or a subroutine. For
  1508. example, the following excerpt is valid:
  1509. @smallexample
  1510. implicit none
  1511. external sub
  1512. pointer (subptr,subpte)
  1513. external subpte
  1514. subptr = loc(sub)
  1515. call subpte()
  1516. [...]
  1517. subroutine sub
  1518. [...]
  1519. end subroutine sub
  1520. @end smallexample
  1521. A pointer may be modified during the course of a program, and this
  1522. will change the location to which the pointee refers. However, when
  1523. pointees are passed as arguments, they are treated as ordinary
  1524. variables in the invoked function. Subsequent changes to the pointer
  1525. will not change the base address of the array that was passed.
  1526. @node CONVERT specifier
  1527. @subsection @code{CONVERT} specifier
  1528. @cindex @code{CONVERT} specifier
  1529. GNU Fortran allows the conversion of unformatted data between little-
  1530. and big-endian representation to facilitate moving of data
  1531. between different systems. The conversion can be indicated with
  1532. the @code{CONVERT} specifier on the @code{OPEN} statement.
  1533. @xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
  1534. the data format via an environment variable.
  1535. Valid values for @code{CONVERT} are:
  1536. @itemize @w{}
  1537. @item @code{CONVERT='NATIVE'} Use the native format. This is the default.
  1538. @item @code{CONVERT='SWAP'} Swap between little- and big-endian.
  1539. @item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
  1540. for unformatted files.
  1541. @item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
  1542. unformatted files.
  1543. @end itemize
  1544. Using the option could look like this:
  1545. @smallexample
  1546. open(file='big.dat',form='unformatted',access='sequential', &
  1547. convert='big_endian')
  1548. @end smallexample
  1549. The value of the conversion can be queried by using
  1550. @code{INQUIRE(CONVERT=ch)}. The values returned are
  1551. @code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
  1552. @code{CONVERT} works between big- and little-endian for
  1553. @code{INTEGER} values of all supported kinds and for @code{REAL}
  1554. on IEEE systems of kinds 4 and 8. Conversion between different
  1555. ``extended double'' types on different architectures such as
  1556. m68k and x86_64, which GNU Fortran
  1557. supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
  1558. probably not work.
  1559. @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
  1560. environment variable will override the CONVERT specifier in the
  1561. open statement}. This is to give control over data formats to
  1562. users who do not have the source code of their program available.
  1563. Using anything but the native representation for unformatted data
  1564. carries a significant speed overhead. If speed in this area matters
  1565. to you, it is best if you use this only for data that needs to be
  1566. portable.
  1567. @node OpenMP
  1568. @subsection OpenMP
  1569. @cindex OpenMP
  1570. OpenMP (Open Multi-Processing) is an application programming
  1571. interface (API) that supports multi-platform shared memory
  1572. multiprocessing programming in C/C++ and Fortran on many
  1573. architectures, including Unix and Microsoft Windows platforms.
  1574. It consists of a set of compiler directives, library routines,
  1575. and environment variables that influence run-time behavior.
  1576. GNU Fortran strives to be compatible to the
  1577. @uref{http://openmp.org/wp/openmp-specifications/,
  1578. OpenMP Application Program Interface v4.0}.
  1579. To enable the processing of the OpenMP directive @code{!$omp} in
  1580. free-form source code; the @code{c$omp}, @code{*$omp} and @code{!$omp}
  1581. directives in fixed form; the @code{!$} conditional compilation sentinels
  1582. in free form; and the @code{c$}, @code{*$} and @code{!$} sentinels
  1583. in fixed form, @command{gfortran} needs to be invoked with the
  1584. @option{-fopenmp}. This also arranges for automatic linking of the
  1585. GNU Offloading and Multi Processing Runtime Library
  1586. @ref{Top,,libgomp,libgomp,GNU Offloading and Multi Processing Runtime
  1587. Library}.
  1588. The OpenMP Fortran runtime library routines are provided both in a
  1589. form of a Fortran 90 module named @code{omp_lib} and in a form of
  1590. a Fortran @code{include} file named @file{omp_lib.h}.
  1591. An example of a parallelized loop taken from Appendix A.1 of
  1592. the OpenMP Application Program Interface v2.5:
  1593. @smallexample
  1594. SUBROUTINE A1(N, A, B)
  1595. INTEGER I, N
  1596. REAL B(N), A(N)
  1597. !$OMP PARALLEL DO !I is private by default
  1598. DO I=2,N
  1599. B(I) = (A(I) + A(I-1)) / 2.0
  1600. ENDDO
  1601. !$OMP END PARALLEL DO
  1602. END SUBROUTINE A1
  1603. @end smallexample
  1604. Please note:
  1605. @itemize
  1606. @item
  1607. @option{-fopenmp} implies @option{-frecursive}, i.e., all local arrays
  1608. will be allocated on the stack. When porting existing code to OpenMP,
  1609. this may lead to surprising results, especially to segmentation faults
  1610. if the stacksize is limited.
  1611. @item
  1612. On glibc-based systems, OpenMP enabled applications cannot be statically
  1613. linked due to limitations of the underlying pthreads-implementation. It
  1614. might be possible to get a working solution if
  1615. @command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
  1616. to the command line. However, this is not supported by @command{gcc} and
  1617. thus not recommended.
  1618. @end itemize
  1619. @node OpenACC
  1620. @subsection OpenACC
  1621. @cindex OpenACC
  1622. OpenACC is an application programming interface (API) that supports
  1623. offloading of code to accelerator devices. It consists of a set of
  1624. compiler directives, library routines, and environment variables that
  1625. influence run-time behavior.
  1626. GNU Fortran strives to be compatible to the
  1627. @uref{http://www.openacc.org/, OpenACC Application Programming
  1628. Interface v2.0}.
  1629. To enable the processing of the OpenACC directive @code{!$acc} in
  1630. free-form source code; the @code{c$acc}, @code{*$acc} and @code{!$acc}
  1631. directives in fixed form; the @code{!$} conditional compilation
  1632. sentinels in free form; and the @code{c$}, @code{*$} and @code{!$}
  1633. sentinels in fixed form, @command{gfortran} needs to be invoked with
  1634. the @option{-fopenacc}. This also arranges for automatic linking of
  1635. the GNU Offloading and Multi Processing Runtime Library
  1636. @ref{Top,,libgomp,libgomp,GNU Offloading and Multi Processing Runtime
  1637. Library}.
  1638. The OpenACC Fortran runtime library routines are provided both in a
  1639. form of a Fortran 90 module named @code{openacc} and in a form of a
  1640. Fortran @code{include} file named @file{openacc_lib.h}.
  1641. Note that this is an experimental feature, incomplete, and subject to
  1642. change in future versions of GCC. See
  1643. @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
  1644. @node Argument list functions
  1645. @subsection Argument list functions @code{%VAL}, @code{%REF} and @code{%LOC}
  1646. @cindex argument list functions
  1647. @cindex @code{%VAL}
  1648. @cindex @code{%REF}
  1649. @cindex @code{%LOC}
  1650. GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
  1651. and @code{%LOC} statements, for backward compatibility with g77.
  1652. It is recommended that these should be used only for code that is
  1653. accessing facilities outside of GNU Fortran, such as operating system
  1654. or windowing facilities. It is best to constrain such uses to isolated
  1655. portions of a program--portions that deal specifically and exclusively
  1656. with low-level, system-dependent facilities. Such portions might well
  1657. provide a portable interface for use by the program as a whole, but are
  1658. themselves not portable, and should be thoroughly tested each time they
  1659. are rebuilt using a new compiler or version of a compiler.
  1660. @code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
  1661. reference and @code{%LOC} passes its memory location. Since gfortran
  1662. already passes scalar arguments by reference, @code{%REF} is in effect
  1663. a do-nothing. @code{%LOC} has the same effect as a Fortran pointer.
  1664. An example of passing an argument by value to a C subroutine foo.:
  1665. @smallexample
  1666. C
  1667. C prototype void foo_ (float x);
  1668. C
  1669. external foo
  1670. real*4 x
  1671. x = 3.14159
  1672. call foo (%VAL (x))
  1673. end
  1674. @end smallexample
  1675. For details refer to the g77 manual
  1676. @uref{https://gcc.gnu.org/@/onlinedocs/@/gcc-3.4.6/@/g77/@/index.html#Top}.
  1677. Also, @code{c_by_val.f} and its partner @code{c_by_val.c} of the
  1678. GNU Fortran testsuite are worth a look.
  1679. @node Read/Write after EOF marker
  1680. @subsection Read/Write after EOF marker
  1681. @cindex @code{EOF}
  1682. @cindex @code{BACKSPACE}
  1683. @cindex @code{REWIND}
  1684. Some legacy codes rely on allowing @code{READ} or @code{WRITE} after the
  1685. EOF file marker in order to find the end of a file. GNU Fortran normally
  1686. rejects these codes with a run-time error message and suggests the user
  1687. consider @code{BACKSPACE} or @code{REWIND} to properly position
  1688. the file before the EOF marker. As an extension, the run-time error may
  1689. be disabled using -std=legacy.
  1690. @node Extensions not implemented in GNU Fortran
  1691. @section Extensions not implemented in GNU Fortran
  1692. @cindex extensions, not implemented
  1693. The long history of the Fortran language, its wide use and broad
  1694. userbase, the large number of different compiler vendors and the lack of
  1695. some features crucial to users in the first standards have lead to the
  1696. existence of a number of important extensions to the language. While
  1697. some of the most useful or popular extensions are supported by the GNU
  1698. Fortran compiler, not all existing extensions are supported. This section
  1699. aims at listing these extensions and offering advice on how best make
  1700. code that uses them running with the GNU Fortran compiler.
  1701. @c More can be found here:
  1702. @c -- https://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Missing-Features.html
  1703. @c -- the list of Fortran and libgfortran bugs closed as WONTFIX:
  1704. @c http://tinyurl.com/2u4h5y
  1705. @menu
  1706. * STRUCTURE and RECORD::
  1707. @c * UNION and MAP::
  1708. * ENCODE and DECODE statements::
  1709. * Variable FORMAT expressions::
  1710. @c * Q edit descriptor::
  1711. @c * AUTOMATIC statement::
  1712. @c * TYPE and ACCEPT I/O Statements::
  1713. @c * .XOR. operator::
  1714. @c * CARRIAGECONTROL, DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
  1715. @c * Omitted arguments in procedure call::
  1716. * Alternate complex function syntax::
  1717. * Volatile COMMON blocks::
  1718. @end menu
  1719. @node STRUCTURE and RECORD
  1720. @subsection @code{STRUCTURE} and @code{RECORD}
  1721. @cindex @code{STRUCTURE}
  1722. @cindex @code{RECORD}
  1723. Record structures are a pre-Fortran-90 vendor extension to create
  1724. user-defined aggregate data types. GNU Fortran does not support
  1725. record structures, only Fortran 90's ``derived types'', which have
  1726. a different syntax.
  1727. In many cases, record structures can easily be converted to derived types.
  1728. To convert, replace @code{STRUCTURE /}@var{structure-name}@code{/}
  1729. by @code{TYPE} @var{type-name}. Additionally, replace
  1730. @code{RECORD /}@var{structure-name}@code{/} by
  1731. @code{TYPE(}@var{type-name}@code{)}. Finally, in the component access,
  1732. replace the period (@code{.}) by the percent sign (@code{%}).
  1733. Here is an example of code using the non portable record structure syntax:
  1734. @example
  1735. ! Declaring a structure named ``item'' and containing three fields:
  1736. ! an integer ID, an description string and a floating-point price.
  1737. STRUCTURE /item/
  1738. INTEGER id
  1739. CHARACTER(LEN=200) description
  1740. REAL price
  1741. END STRUCTURE
  1742. ! Define two variables, an single record of type ``item''
  1743. ! named ``pear'', and an array of items named ``store_catalog''
  1744. RECORD /item/ pear, store_catalog(100)
  1745. ! We can directly access the fields of both variables
  1746. pear.id = 92316
  1747. pear.description = "juicy D'Anjou pear"
  1748. pear.price = 0.15
  1749. store_catalog(7).id = 7831
  1750. store_catalog(7).description = "milk bottle"
  1751. store_catalog(7).price = 1.2
  1752. ! We can also manipulate the whole structure
  1753. store_catalog(12) = pear
  1754. print *, store_catalog(12)
  1755. @end example
  1756. @noindent
  1757. This code can easily be rewritten in the Fortran 90 syntax as following:
  1758. @example
  1759. ! ``STRUCTURE /name/ ... END STRUCTURE'' becomes
  1760. ! ``TYPE name ... END TYPE''
  1761. TYPE item
  1762. INTEGER id
  1763. CHARACTER(LEN=200) description
  1764. REAL price
  1765. END TYPE
  1766. ! ``RECORD /name/ variable'' becomes ``TYPE(name) variable''
  1767. TYPE(item) pear, store_catalog(100)
  1768. ! Instead of using a dot (.) to access fields of a record, the
  1769. ! standard syntax uses a percent sign (%)
  1770. pear%id = 92316
  1771. pear%description = "juicy D'Anjou pear"
  1772. pear%price = 0.15
  1773. store_catalog(7)%id = 7831
  1774. store_catalog(7)%description = "milk bottle"
  1775. store_catalog(7)%price = 1.2
  1776. ! Assignments of a whole variable do not change
  1777. store_catalog(12) = pear
  1778. print *, store_catalog(12)
  1779. @end example
  1780. @c @node UNION and MAP
  1781. @c @subsection @code{UNION} and @code{MAP}
  1782. @c @cindex @code{UNION}
  1783. @c @cindex @code{MAP}
  1784. @c
  1785. @c For help writing this one, see
  1786. @c http://www.eng.umd.edu/~nsw/ench250/fortran1.htm#UNION and
  1787. @c http://www.tacc.utexas.edu/services/userguides/pgi/pgiws_ug/pgi32u06.htm
  1788. @node ENCODE and DECODE statements
  1789. @subsection @code{ENCODE} and @code{DECODE} statements
  1790. @cindex @code{ENCODE}
  1791. @cindex @code{DECODE}
  1792. GNU Fortran does not support the @code{ENCODE} and @code{DECODE}
  1793. statements. These statements are best replaced by @code{READ} and
  1794. @code{WRITE} statements involving internal files (@code{CHARACTER}
  1795. variables and arrays), which have been part of the Fortran standard since
  1796. Fortran 77. For example, replace a code fragment like
  1797. @smallexample
  1798. INTEGER*1 LINE(80)
  1799. REAL A, B, C
  1800. c ... Code that sets LINE
  1801. DECODE (80, 9000, LINE) A, B, C
  1802. 9000 FORMAT (1X, 3(F10.5))
  1803. @end smallexample
  1804. @noindent
  1805. with the following:
  1806. @smallexample
  1807. CHARACTER(LEN=80) LINE
  1808. REAL A, B, C
  1809. c ... Code that sets LINE
  1810. READ (UNIT=LINE, FMT=9000) A, B, C
  1811. 9000 FORMAT (1X, 3(F10.5))
  1812. @end smallexample
  1813. Similarly, replace a code fragment like
  1814. @smallexample
  1815. INTEGER*1 LINE(80)
  1816. REAL A, B, C
  1817. c ... Code that sets A, B and C
  1818. ENCODE (80, 9000, LINE) A, B, C
  1819. 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
  1820. @end smallexample
  1821. @noindent
  1822. with the following:
  1823. @smallexample
  1824. CHARACTER(LEN=80) LINE
  1825. REAL A, B, C
  1826. c ... Code that sets A, B and C
  1827. WRITE (UNIT=LINE, FMT=9000) A, B, C
  1828. 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
  1829. @end smallexample
  1830. @node Variable FORMAT expressions
  1831. @subsection Variable @code{FORMAT} expressions
  1832. @cindex @code{FORMAT}
  1833. A variable @code{FORMAT} expression is format statement which includes
  1834. angle brackets enclosing a Fortran expression: @code{FORMAT(I<N>)}. GNU
  1835. Fortran does not support this legacy extension. The effect of variable
  1836. format expressions can be reproduced by using the more powerful (and
  1837. standard) combination of internal output and string formats. For example,
  1838. replace a code fragment like this:
  1839. @smallexample
  1840. WRITE(6,20) INT1
  1841. 20 FORMAT(I<N+1>)
  1842. @end smallexample
  1843. @noindent
  1844. with the following:
  1845. @smallexample
  1846. c Variable declaration
  1847. CHARACTER(LEN=20) FMT
  1848. c
  1849. c Other code here...
  1850. c
  1851. WRITE(FMT,'("(I", I0, ")")') N+1
  1852. WRITE(6,FMT) INT1
  1853. @end smallexample
  1854. @noindent
  1855. or with:
  1856. @smallexample
  1857. c Variable declaration
  1858. CHARACTER(LEN=20) FMT
  1859. c
  1860. c Other code here...
  1861. c
  1862. WRITE(FMT,*) N+1
  1863. WRITE(6,"(I" // ADJUSTL(FMT) // ")") INT1
  1864. @end smallexample
  1865. @node Alternate complex function syntax
  1866. @subsection Alternate complex function syntax
  1867. @cindex Complex function
  1868. Some Fortran compilers, including @command{g77}, let the user declare
  1869. complex functions with the syntax @code{COMPLEX FUNCTION name*16()}, as
  1870. well as @code{COMPLEX*16 FUNCTION name()}. Both are non-standard, legacy
  1871. extensions. @command{gfortran} accepts the latter form, which is more
  1872. common, but not the former.
  1873. @node Volatile COMMON blocks
  1874. @subsection Volatile @code{COMMON} blocks
  1875. @cindex @code{VOLATILE}
  1876. @cindex @code{COMMON}
  1877. Some Fortran compilers, including @command{g77}, let the user declare
  1878. @code{COMMON} with the @code{VOLATILE} attribute. This is
  1879. invalid standard Fortran syntax and is not supported by
  1880. @command{gfortran}. Note that @command{gfortran} accepts
  1881. @code{VOLATILE} variables in @code{COMMON} blocks since revision 4.3.
  1882. @c ---------------------------------------------------------------------
  1883. @c Mixed-Language Programming
  1884. @c ---------------------------------------------------------------------
  1885. @node Mixed-Language Programming
  1886. @chapter Mixed-Language Programming
  1887. @cindex Interoperability
  1888. @cindex Mixed-language programming
  1889. @menu
  1890. * Interoperability with C::
  1891. * GNU Fortran Compiler Directives::
  1892. * Non-Fortran Main Program::
  1893. * Naming and argument-passing conventions::
  1894. @end menu
  1895. This chapter is about mixed-language interoperability, but also applies
  1896. if one links Fortran code compiled by different compilers. In most cases,
  1897. use of the C Binding features of the Fortran 2003 standard is sufficient,
  1898. and their use is highly recommended.
  1899. @node Interoperability with C
  1900. @section Interoperability with C
  1901. @menu
  1902. * Intrinsic Types::
  1903. * Derived Types and struct::
  1904. * Interoperable Global Variables::
  1905. * Interoperable Subroutines and Functions::
  1906. * Working with Pointers::
  1907. * Further Interoperability of Fortran with C::
  1908. @end menu
  1909. Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
  1910. standardized way to generate procedure and derived-type
  1911. declarations and global variables which are interoperable with C
  1912. (ISO/IEC 9899:1999). The @code{bind(C)} attribute has been added
  1913. to inform the compiler that a symbol shall be interoperable with C;
  1914. also, some constraints are added. Note, however, that not
  1915. all C features have a Fortran equivalent or vice versa. For instance,
  1916. neither C's unsigned integers nor C's functions with variable number
  1917. of arguments have an equivalent in Fortran.
  1918. Note that array dimensions are reversely ordered in C and that arrays in
  1919. C always start with index 0 while in Fortran they start by default with
  1920. 1. Thus, an array declaration @code{A(n,m)} in Fortran matches
  1921. @code{A[m][n]} in C and accessing the element @code{A(i,j)} matches
  1922. @code{A[j-1][i-1]}. The element following @code{A(i,j)} (C: @code{A[j-1][i-1]};
  1923. assuming @math{i < n}) in memory is @code{A(i+1,j)} (C: @code{A[j-1][i]}).
  1924. @node Intrinsic Types
  1925. @subsection Intrinsic Types
  1926. In order to ensure that exactly the same variable type and kind is used
  1927. in C and Fortran, the named constants shall be used which are defined in the
  1928. @code{ISO_C_BINDING} intrinsic module. That module contains named constants
  1929. for kind parameters and character named constants for the escape sequences
  1930. in C. For a list of the constants, see @ref{ISO_C_BINDING}.
  1931. For logical types, please note that the Fortran standard only guarantees
  1932. interoperability between C99's @code{_Bool} and Fortran's @code{C_Bool}-kind
  1933. logicals and C99 defines that @code{true} has the value 1 and @code{false}
  1934. the value 0. Using any other integer value with GNU Fortran's @code{LOGICAL}
  1935. (with any kind parameter) gives an undefined result. (Passing other integer
  1936. values than 0 and 1 to GCC's @code{_Bool} is also undefined, unless the
  1937. integer is explicitly or implicitly casted to @code{_Bool}.)
  1938. @node Derived Types and struct
  1939. @subsection Derived Types and struct
  1940. For compatibility of derived types with @code{struct}, one needs to use
  1941. the @code{BIND(C)} attribute in the type declaration. For instance, the
  1942. following type declaration
  1943. @smallexample
  1944. USE ISO_C_BINDING
  1945. TYPE, BIND(C) :: myType
  1946. INTEGER(C_INT) :: i1, i2
  1947. INTEGER(C_SIGNED_CHAR) :: i3
  1948. REAL(C_DOUBLE) :: d1
  1949. COMPLEX(C_FLOAT_COMPLEX) :: c1
  1950. CHARACTER(KIND=C_CHAR) :: str(5)
  1951. END TYPE
  1952. @end smallexample
  1953. matches the following @code{struct} declaration in C
  1954. @smallexample
  1955. struct @{
  1956. int i1, i2;
  1957. /* Note: "char" might be signed or unsigned. */
  1958. signed char i3;
  1959. double d1;
  1960. float _Complex c1;
  1961. char str[5];
  1962. @} myType;
  1963. @end smallexample
  1964. Derived types with the C binding attribute shall not have the @code{sequence}
  1965. attribute, type parameters, the @code{extends} attribute, nor type-bound
  1966. procedures. Every component must be of interoperable type and kind and may not
  1967. have the @code{pointer} or @code{allocatable} attribute. The names of the
  1968. components are irrelevant for interoperability.
  1969. As there exist no direct Fortran equivalents, neither unions nor structs
  1970. with bit field or variable-length array members are interoperable.
  1971. @node Interoperable Global Variables
  1972. @subsection Interoperable Global Variables
  1973. Variables can be made accessible from C using the C binding attribute,
  1974. optionally together with specifying a binding name. Those variables
  1975. have to be declared in the declaration part of a @code{MODULE},
  1976. be of interoperable type, and have neither the @code{pointer} nor
  1977. the @code{allocatable} attribute.
  1978. @smallexample
  1979. MODULE m
  1980. USE myType_module
  1981. USE ISO_C_BINDING
  1982. integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag
  1983. type(myType), bind(C) :: tp
  1984. END MODULE
  1985. @end smallexample
  1986. Here, @code{_MyProject_flags} is the case-sensitive name of the variable
  1987. as seen from C programs while @code{global_flag} is the case-insensitive
  1988. name as seen from Fortran. If no binding name is specified, as for
  1989. @var{tp}, the C binding name is the (lowercase) Fortran binding name.
  1990. If a binding name is specified, only a single variable may be after the
  1991. double colon. Note of warning: You cannot use a global variable to
  1992. access @var{errno} of the C library as the C standard allows it to be
  1993. a macro. Use the @code{IERRNO} intrinsic (GNU extension) instead.
  1994. @node Interoperable Subroutines and Functions
  1995. @subsection Interoperable Subroutines and Functions
  1996. Subroutines and functions have to have the @code{BIND(C)} attribute to
  1997. be compatible with C. The dummy argument declaration is relatively
  1998. straightforward. However, one needs to be careful because C uses
  1999. call-by-value by default while Fortran behaves usually similar to
  2000. call-by-reference. Furthermore, strings and pointers are handled
  2001. differently. Note that in Fortran 2003 and 2008 only explicit size
  2002. and assumed-size arrays are supported but not assumed-shape or
  2003. deferred-shape (i.e. allocatable or pointer) arrays. However, those
  2004. are allowed since the Technical Specification 29113, see
  2005. @ref{Further Interoperability of Fortran with C}
  2006. To pass a variable by value, use the @code{VALUE} attribute.
  2007. Thus, the following C prototype
  2008. @smallexample
  2009. @code{int func(int i, int *j)}
  2010. @end smallexample
  2011. matches the Fortran declaration
  2012. @smallexample
  2013. integer(c_int) function func(i,j)
  2014. use iso_c_binding, only: c_int
  2015. integer(c_int), VALUE :: i
  2016. integer(c_int) :: j
  2017. @end smallexample
  2018. Note that pointer arguments also frequently need the @code{VALUE} attribute,
  2019. see @ref{Working with Pointers}.
  2020. Strings are handled quite differently in C and Fortran. In C a string
  2021. is a @code{NUL}-terminated array of characters while in Fortran each string
  2022. has a length associated with it and is thus not terminated (by e.g.
  2023. @code{NUL}). For example, if one wants to use the following C function,
  2024. @smallexample
  2025. #include <stdio.h>
  2026. void print_C(char *string) /* equivalent: char string[] */
  2027. @{
  2028. printf("%s\n", string);
  2029. @}
  2030. @end smallexample
  2031. to print ``Hello World'' from Fortran, one can call it using
  2032. @smallexample
  2033. use iso_c_binding, only: C_CHAR, C_NULL_CHAR
  2034. interface
  2035. subroutine print_c(string) bind(C, name="print_C")
  2036. use iso_c_binding, only: c_char
  2037. character(kind=c_char) :: string(*)
  2038. end subroutine print_c
  2039. end interface
  2040. call print_c(C_CHAR_"Hello World"//C_NULL_CHAR)
  2041. @end smallexample
  2042. As the example shows, one needs to ensure that the
  2043. string is @code{NUL} terminated. Additionally, the dummy argument
  2044. @var{string} of @code{print_C} is a length-one assumed-size
  2045. array; using @code{character(len=*)} is not allowed. The example
  2046. above uses @code{c_char_"Hello World"} to ensure the string
  2047. literal has the right type; typically the default character
  2048. kind and @code{c_char} are the same and thus @code{"Hello World"}
  2049. is equivalent. However, the standard does not guarantee this.
  2050. The use of strings is now further illustrated using the C library
  2051. function @code{strncpy}, whose prototype is
  2052. @smallexample
  2053. char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
  2054. @end smallexample
  2055. The function @code{strncpy} copies at most @var{n} characters from
  2056. string @var{s2} to @var{s1} and returns @var{s1}. In the following
  2057. example, we ignore the return value:
  2058. @smallexample
  2059. use iso_c_binding
  2060. implicit none
  2061. character(len=30) :: str,str2
  2062. interface
  2063. ! Ignore the return value of strncpy -> subroutine
  2064. ! "restrict" is always assumed if we do not pass a pointer
  2065. subroutine strncpy(dest, src, n) bind(C)
  2066. import
  2067. character(kind=c_char), intent(out) :: dest(*)
  2068. character(kind=c_char), intent(in) :: src(*)
  2069. integer(c_size_t), value, intent(in) :: n
  2070. end subroutine strncpy
  2071. end interface
  2072. str = repeat('X',30) ! Initialize whole string with 'X'
  2073. call strncpy(str, c_char_"Hello World"//C_NULL_CHAR, &
  2074. len(c_char_"Hello World",kind=c_size_t))
  2075. print '(a)', str ! prints: "Hello WorldXXXXXXXXXXXXXXXXXXX"
  2076. end
  2077. @end smallexample
  2078. The intrinsic procedures are described in @ref{Intrinsic Procedures}.
  2079. @node Working with Pointers
  2080. @subsection Working with Pointers
  2081. C pointers are represented in Fortran via the special opaque derived type
  2082. @code{type(c_ptr)} (with private components). Thus one needs to
  2083. use intrinsic conversion procedures to convert from or to C pointers.
  2084. For some applications, using an assumed type (@code{TYPE(*)}) can be an
  2085. alternative to a C pointer; see
  2086. @ref{Further Interoperability of Fortran with C}.
  2087. For example,
  2088. @smallexample
  2089. use iso_c_binding
  2090. type(c_ptr) :: cptr1, cptr2
  2091. integer, target :: array(7), scalar
  2092. integer, pointer :: pa(:), ps
  2093. cptr1 = c_loc(array(1)) ! The programmer needs to ensure that the
  2094. ! array is contiguous if required by the C
  2095. ! procedure
  2096. cptr2 = c_loc(scalar)
  2097. call c_f_pointer(cptr2, ps)
  2098. call c_f_pointer(cptr2, pa, shape=[7])
  2099. @end smallexample
  2100. When converting C to Fortran arrays, the one-dimensional @code{SHAPE} argument
  2101. has to be passed.
  2102. If a pointer is a dummy-argument of an interoperable procedure, it usually
  2103. has to be declared using the @code{VALUE} attribute. @code{void*}
  2104. matches @code{TYPE(C_PTR), VALUE}, while @code{TYPE(C_PTR)} alone
  2105. matches @code{void**}.
  2106. Procedure pointers are handled analogously to pointers; the C type is
  2107. @code{TYPE(C_FUNPTR)} and the intrinsic conversion procedures are
  2108. @code{C_F_PROCPOINTER} and @code{C_FUNLOC}.
  2109. Let us consider two examples of actually passing a procedure pointer from
  2110. C to Fortran and vice versa. Note that these examples are also very
  2111. similar to passing ordinary pointers between both languages. First,
  2112. consider this code in C:
  2113. @smallexample
  2114. /* Procedure implemented in Fortran. */
  2115. void get_values (void (*)(double));
  2116. /* Call-back routine we want called from Fortran. */
  2117. void
  2118. print_it (double x)
  2119. @{
  2120. printf ("Number is %f.\n", x);
  2121. @}
  2122. /* Call Fortran routine and pass call-back to it. */
  2123. void
  2124. foobar ()
  2125. @{
  2126. get_values (&print_it);
  2127. @}
  2128. @end smallexample
  2129. A matching implementation for @code{get_values} in Fortran, that correctly
  2130. receives the procedure pointer from C and is able to call it, is given
  2131. in the following @code{MODULE}:
  2132. @smallexample
  2133. MODULE m
  2134. IMPLICIT NONE
  2135. ! Define interface of call-back routine.
  2136. ABSTRACT INTERFACE
  2137. SUBROUTINE callback (x)
  2138. USE, INTRINSIC :: ISO_C_BINDING
  2139. REAL(KIND=C_DOUBLE), INTENT(IN), VALUE :: x
  2140. END SUBROUTINE callback
  2141. END INTERFACE
  2142. CONTAINS
  2143. ! Define C-bound procedure.
  2144. SUBROUTINE get_values (cproc) BIND(C)
  2145. USE, INTRINSIC :: ISO_C_BINDING
  2146. TYPE(C_FUNPTR), INTENT(IN), VALUE :: cproc
  2147. PROCEDURE(callback), POINTER :: proc
  2148. ! Convert C to Fortran procedure pointer.
  2149. CALL C_F_PROCPOINTER (cproc, proc)
  2150. ! Call it.
  2151. CALL proc (1.0_C_DOUBLE)
  2152. CALL proc (-42.0_C_DOUBLE)
  2153. CALL proc (18.12_C_DOUBLE)
  2154. END SUBROUTINE get_values
  2155. END MODULE m
  2156. @end smallexample
  2157. Next, we want to call a C routine that expects a procedure pointer argument
  2158. and pass it a Fortran procedure (which clearly must be interoperable!).
  2159. Again, the C function may be:
  2160. @smallexample
  2161. int
  2162. call_it (int (*func)(int), int arg)
  2163. @{
  2164. return func (arg);
  2165. @}
  2166. @end smallexample
  2167. It can be used as in the following Fortran code:
  2168. @smallexample
  2169. MODULE m
  2170. USE, INTRINSIC :: ISO_C_BINDING
  2171. IMPLICIT NONE
  2172. ! Define interface of C function.
  2173. INTERFACE
  2174. INTEGER(KIND=C_INT) FUNCTION call_it (func, arg) BIND(C)
  2175. USE, INTRINSIC :: ISO_C_BINDING
  2176. TYPE(C_FUNPTR), INTENT(IN), VALUE :: func
  2177. INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
  2178. END FUNCTION call_it
  2179. END INTERFACE
  2180. CONTAINS
  2181. ! Define procedure passed to C function.
  2182. ! It must be interoperable!
  2183. INTEGER(KIND=C_INT) FUNCTION double_it (arg) BIND(C)
  2184. INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
  2185. double_it = arg + arg
  2186. END FUNCTION double_it
  2187. ! Call C function.
  2188. SUBROUTINE foobar ()
  2189. TYPE(C_FUNPTR) :: cproc
  2190. INTEGER(KIND=C_INT) :: i
  2191. ! Get C procedure pointer.
  2192. cproc = C_FUNLOC (double_it)
  2193. ! Use it.
  2194. DO i = 1_C_INT, 10_C_INT
  2195. PRINT *, call_it (cproc, i)
  2196. END DO
  2197. END SUBROUTINE foobar
  2198. END MODULE m
  2199. @end smallexample
  2200. @node Further Interoperability of Fortran with C
  2201. @subsection Further Interoperability of Fortran with C
  2202. The Technical Specification ISO/IEC TS 29113:2012 on further
  2203. interoperability of Fortran with C extends the interoperability support
  2204. of Fortran 2003 and Fortran 2008. Besides removing some restrictions
  2205. and constraints, it adds assumed-type (@code{TYPE(*)}) and assumed-rank
  2206. (@code{dimension}) variables and allows for interoperability of
  2207. assumed-shape, assumed-rank and deferred-shape arrays, including
  2208. allocatables and pointers.
  2209. Note: Currently, GNU Fortran does not support the array descriptor
  2210. (dope vector) as specified in the Technical Specification, but uses
  2211. an array descriptor with different fields. The Chasm Language
  2212. Interoperability Tools, @url{http://chasm-interop.sourceforge.net/},
  2213. provide an interface to GNU Fortran's array descriptor.
  2214. The Technical Specification adds the following new features, which
  2215. are supported by GNU Fortran:
  2216. @itemize @bullet
  2217. @item The @code{ASYNCHRONOUS} attribute has been clarified and
  2218. extended to allow its use with asynchronous communication in
  2219. user-provided libraries such as in implementations of the
  2220. Message Passing Interface specification.
  2221. @item Many constraints have been relaxed, in particular for
  2222. the @code{C_LOC} and @code{C_F_POINTER} intrinsics.
  2223. @item The @code{OPTIONAL} attribute is now allowed for dummy
  2224. arguments; an absent argument matches a @code{NULL} pointer.
  2225. @item Assumed types (@code{TYPE(*)}) have been added, which may
  2226. only be used for dummy arguments. They are unlimited polymorphic
  2227. but contrary to @code{CLASS(*)} they do not contain any type
  2228. information, similar to C's @code{void *} pointers. Expressions
  2229. of any type and kind can be passed; thus, it can be used as
  2230. replacement for @code{TYPE(C_PTR)}, avoiding the use of
  2231. @code{C_LOC} in the caller.
  2232. Note, however, that @code{TYPE(*)} only accepts scalar arguments,
  2233. unless the @code{DIMENSION} is explicitly specified. As
  2234. @code{DIMENSION(*)} only supports array (including array elements) but
  2235. no scalars, it is not a full replacement for @code{C_LOC}. On the
  2236. other hand, assumed-type assumed-rank dummy arguments
  2237. (@code{TYPE(*), DIMENSION(..)}) allow for both scalars and arrays, but
  2238. require special code on the callee side to handle the array descriptor.
  2239. @item Assumed-rank arrays (@code{DIMENSION(..)}) as dummy argument
  2240. allow that scalars and arrays of any rank can be passed as actual
  2241. argument. As the Technical Specification does not provide for direct
  2242. means to operate with them, they have to be used either from the C side
  2243. or be converted using @code{C_LOC} and @code{C_F_POINTER} to scalars
  2244. or arrays of a specific rank. The rank can be determined using the
  2245. @code{RANK} intrinisic.
  2246. @end itemize
  2247. Currently unimplemented:
  2248. @itemize @bullet
  2249. @item GNU Fortran always uses an array descriptor, which does not
  2250. match the one of the Technical Specification. The
  2251. @code{ISO_Fortran_binding.h} header file and the C functions it
  2252. specifies are not available.
  2253. @item Using assumed-shape, assumed-rank and deferred-shape arrays in
  2254. @code{BIND(C)} procedures is not fully supported. In particular,
  2255. C interoperable strings of other length than one are not supported
  2256. as this requires the new array descriptor.
  2257. @end itemize
  2258. @node GNU Fortran Compiler Directives
  2259. @section GNU Fortran Compiler Directives
  2260. The Fortran standard describes how a conforming program shall
  2261. behave; however, the exact implementation is not standardized. In order
  2262. to allow the user to choose specific implementation details, compiler
  2263. directives can be used to set attributes of variables and procedures
  2264. which are not part of the standard. Whether a given attribute is
  2265. supported and its exact effects depend on both the operating system and
  2266. on the processor; see
  2267. @ref{Top,,C Extensions,gcc,Using the GNU Compiler Collection (GCC)}
  2268. for details.
  2269. For procedures and procedure pointers, the following attributes can
  2270. be used to change the calling convention:
  2271. @itemize
  2272. @item @code{CDECL} -- standard C calling convention
  2273. @item @code{STDCALL} -- convention where the called procedure pops the stack
  2274. @item @code{FASTCALL} -- part of the arguments are passed via registers
  2275. instead using the stack
  2276. @end itemize
  2277. Besides changing the calling convention, the attributes also influence
  2278. the decoration of the symbol name, e.g., by a leading underscore or by
  2279. a trailing at-sign followed by the number of bytes on the stack. When
  2280. assigning a procedure to a procedure pointer, both should use the same
  2281. calling convention.
  2282. On some systems, procedures and global variables (module variables and
  2283. @code{COMMON} blocks) need special handling to be accessible when they
  2284. are in a shared library. The following attributes are available:
  2285. @itemize
  2286. @item @code{DLLEXPORT} -- provide a global pointer to a pointer in the DLL
  2287. @item @code{DLLIMPORT} -- reference the function or variable using a
  2288. global pointer
  2289. @end itemize
  2290. For dummy arguments, the @code{NO_ARG_CHECK} attribute can be used; in
  2291. other compilers, it is also known as @code{IGNORE_TKR}. For dummy arguments
  2292. with this attribute actual arguments of any type and kind (similar to
  2293. @code{TYPE(*)}), scalars and arrays of any rank (no equivalent
  2294. in Fortran standard) are accepted. As with @code{TYPE(*)}, the argument
  2295. is unlimited polymorphic and no type information is available.
  2296. Additionally, the argument may only be passed to dummy arguments
  2297. with the @code{NO_ARG_CHECK} attribute and as argument to the
  2298. @code{PRESENT} intrinsic function and to @code{C_LOC} of the
  2299. @code{ISO_C_BINDING} module.
  2300. Variables with @code{NO_ARG_CHECK} attribute shall be of assumed-type
  2301. (@code{TYPE(*)}; recommended) or of type @code{INTEGER}, @code{LOGICAL},
  2302. @code{REAL} or @code{COMPLEX}. They shall not have the @code{ALLOCATE},
  2303. @code{CODIMENSION}, @code{INTENT(OUT)}, @code{POINTER} or @code{VALUE}
  2304. attribute; furthermore, they shall be either scalar or of assumed-size
  2305. (@code{dimension(*)}). As @code{TYPE(*)}, the @code{NO_ARG_CHECK} attribute
  2306. requires an explicit interface.
  2307. @itemize
  2308. @item @code{NO_ARG_CHECK} -- disable the type, kind and rank checking
  2309. @end itemize
  2310. The attributes are specified using the syntax
  2311. @code{!GCC$ ATTRIBUTES} @var{attribute-list} @code{::} @var{variable-list}
  2312. where in free-form source code only whitespace is allowed before @code{!GCC$}
  2313. and in fixed-form source code @code{!GCC$}, @code{cGCC$} or @code{*GCC$} shall
  2314. start in the first column.
  2315. For procedures, the compiler directives shall be placed into the body
  2316. of the procedure; for variables and procedure pointers, they shall be in
  2317. the same declaration part as the variable or procedure pointer.
  2318. @node Non-Fortran Main Program
  2319. @section Non-Fortran Main Program
  2320. @menu
  2321. * _gfortran_set_args:: Save command-line arguments
  2322. * _gfortran_set_options:: Set library option flags
  2323. * _gfortran_set_convert:: Set endian conversion
  2324. * _gfortran_set_record_marker:: Set length of record markers
  2325. * _gfortran_set_fpe:: Set when a Floating Point Exception should be raised
  2326. * _gfortran_set_max_subrecord_length:: Set subrecord length
  2327. @end menu
  2328. Even if you are doing mixed-language programming, it is very
  2329. likely that you do not need to know or use the information in this
  2330. section. Since it is about the internal structure of GNU Fortran,
  2331. it may also change in GCC minor releases.
  2332. When you compile a @code{PROGRAM} with GNU Fortran, a function
  2333. with the name @code{main} (in the symbol table of the object file)
  2334. is generated, which initializes the libgfortran library and then
  2335. calls the actual program which uses the name @code{MAIN__}, for
  2336. historic reasons. If you link GNU Fortran compiled procedures
  2337. to, e.g., a C or C++ program or to a Fortran program compiled by
  2338. a different compiler, the libgfortran library is not initialized
  2339. and thus a few intrinsic procedures do not work properly, e.g.
  2340. those for obtaining the command-line arguments.
  2341. Therefore, if your @code{PROGRAM} is not compiled with
  2342. GNU Fortran and the GNU Fortran compiled procedures require
  2343. intrinsics relying on the library initialization, you need to
  2344. initialize the library yourself. Using the default options,
  2345. gfortran calls @code{_gfortran_set_args} and
  2346. @code{_gfortran_set_options}. The initialization of the former
  2347. is needed if the called procedures access the command line
  2348. (and for backtracing); the latter sets some flags based on the
  2349. standard chosen or to enable backtracing. In typical programs,
  2350. it is not necessary to call any initialization function.
  2351. If your @code{PROGRAM} is compiled with GNU Fortran, you shall
  2352. not call any of the following functions. The libgfortran
  2353. initialization functions are shown in C syntax but using C
  2354. bindings they are also accessible from Fortran.
  2355. @node _gfortran_set_args
  2356. @subsection @code{_gfortran_set_args} --- Save command-line arguments
  2357. @fnindex _gfortran_set_args
  2358. @cindex libgfortran initialization, set_args
  2359. @table @asis
  2360. @item @emph{Description}:
  2361. @code{_gfortran_set_args} saves the command-line arguments; this
  2362. initialization is required if any of the command-line intrinsics
  2363. is called. Additionally, it shall be called if backtracing is
  2364. enabled (see @code{_gfortran_set_options}).
  2365. @item @emph{Syntax}:
  2366. @code{void _gfortran_set_args (int argc, char *argv[])}
  2367. @item @emph{Arguments}:
  2368. @multitable @columnfractions .15 .70
  2369. @item @var{argc} @tab number of command line argument strings
  2370. @item @var{argv} @tab the command-line argument strings; argv[0]
  2371. is the pathname of the executable itself.
  2372. @end multitable
  2373. @item @emph{Example}:
  2374. @smallexample
  2375. int main (int argc, char *argv[])
  2376. @{
  2377. /* Initialize libgfortran. */
  2378. _gfortran_set_args (argc, argv);
  2379. return 0;
  2380. @}
  2381. @end smallexample
  2382. @end table
  2383. @node _gfortran_set_options
  2384. @subsection @code{_gfortran_set_options} --- Set library option flags
  2385. @fnindex _gfortran_set_options
  2386. @cindex libgfortran initialization, set_options
  2387. @table @asis
  2388. @item @emph{Description}:
  2389. @code{_gfortran_set_options} sets several flags related to the Fortran
  2390. standard to be used, whether backtracing should be enabled
  2391. and whether range checks should be performed. The syntax allows for
  2392. upward compatibility since the number of passed flags is specified; for
  2393. non-passed flags, the default value is used. See also
  2394. @pxref{Code Gen Options}. Please note that not all flags are actually
  2395. used.
  2396. @item @emph{Syntax}:
  2397. @code{void _gfortran_set_options (int num, int options[])}
  2398. @item @emph{Arguments}:
  2399. @multitable @columnfractions .15 .70
  2400. @item @var{num} @tab number of options passed
  2401. @item @var{argv} @tab The list of flag values
  2402. @end multitable
  2403. @item @emph{option flag list}:
  2404. @multitable @columnfractions .15 .70
  2405. @item @var{option}[0] @tab Allowed standard; can give run-time errors
  2406. if e.g. an input-output edit descriptor is invalid in a given standard.
  2407. Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
  2408. @code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4), @code{GFC_STD_F95}
  2409. (8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU} (32),
  2410. @code{GFC_STD_LEGACY} (64), @code{GFC_STD_F2008} (128),
  2411. @code{GFC_STD_F2008_OBS} (256) and GFC_STD_F2008_TS (512). Default:
  2412. @code{GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F95 | GFC_STD_F2003
  2413. | GFC_STD_F2008 | GFC_STD_F2008_TS | GFC_STD_F2008_OBS | GFC_STD_F77
  2414. | GFC_STD_GNU | GFC_STD_LEGACY}.
  2415. @item @var{option}[1] @tab Standard-warning flag; prints a warning to
  2416. standard error. Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
  2417. @item @var{option}[2] @tab If non zero, enable pedantic checking.
  2418. Default: off.
  2419. @item @var{option}[3] @tab Unused.
  2420. @item @var{option}[4] @tab If non zero, enable backtracing on run-time
  2421. errors. Default: off. (Default in the compiler: on.)
  2422. Note: Installs a signal handler and requires command-line
  2423. initialization using @code{_gfortran_set_args}.
  2424. @item @var{option}[5] @tab If non zero, supports signed zeros.
  2425. Default: enabled.
  2426. @item @var{option}[6] @tab Enables run-time checking. Possible values
  2427. are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
  2428. GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16), GFC_RTCHECK_POINTER (32).
  2429. Default: disabled.
  2430. @item @var{option}[7] @tab Unused.
  2431. @item @var{option}[8] @tab Show a warning when invoking @code{STOP} and
  2432. @code{ERROR STOP} if a floating-point exception occurred. Possible values
  2433. are (bitwise or-ed) @code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
  2434. @code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
  2435. @code{GFC_FPE_UNDERFLOW} (16), @code{GFC_FPE_INEXACT} (32). Default: None (0).
  2436. (Default in the compiler: @code{GFC_FPE_INVALID | GFC_FPE_DENORMAL |
  2437. GFC_FPE_ZERO | GFC_FPE_OVERFLOW | GFC_FPE_UNDERFLOW}.)
  2438. @end multitable
  2439. @item @emph{Example}:
  2440. @smallexample
  2441. /* Use gfortran 4.9 default options. */
  2442. static int options[] = @{68, 511, 0, 0, 1, 1, 0, 0, 31@};
  2443. _gfortran_set_options (9, &options);
  2444. @end smallexample
  2445. @end table
  2446. @node _gfortran_set_convert
  2447. @subsection @code{_gfortran_set_convert} --- Set endian conversion
  2448. @fnindex _gfortran_set_convert
  2449. @cindex libgfortran initialization, set_convert
  2450. @table @asis
  2451. @item @emph{Description}:
  2452. @code{_gfortran_set_convert} set the representation of data for
  2453. unformatted files.
  2454. @item @emph{Syntax}:
  2455. @code{void _gfortran_set_convert (int conv)}
  2456. @item @emph{Arguments}:
  2457. @multitable @columnfractions .15 .70
  2458. @item @var{conv} @tab Endian conversion, possible values:
  2459. GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1),
  2460. GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3).
  2461. @end multitable
  2462. @item @emph{Example}:
  2463. @smallexample
  2464. int main (int argc, char *argv[])
  2465. @{
  2466. /* Initialize libgfortran. */
  2467. _gfortran_set_args (argc, argv);
  2468. _gfortran_set_convert (1);
  2469. return 0;
  2470. @}
  2471. @end smallexample
  2472. @end table
  2473. @node _gfortran_set_record_marker
  2474. @subsection @code{_gfortran_set_record_marker} --- Set length of record markers
  2475. @fnindex _gfortran_set_record_marker
  2476. @cindex libgfortran initialization, set_record_marker
  2477. @table @asis
  2478. @item @emph{Description}:
  2479. @code{_gfortran_set_record_marker} sets the length of record markers
  2480. for unformatted files.
  2481. @item @emph{Syntax}:
  2482. @code{void _gfortran_set_record_marker (int val)}
  2483. @item @emph{Arguments}:
  2484. @multitable @columnfractions .15 .70
  2485. @item @var{val} @tab Length of the record marker; valid values
  2486. are 4 and 8. Default is 4.
  2487. @end multitable
  2488. @item @emph{Example}:
  2489. @smallexample
  2490. int main (int argc, char *argv[])
  2491. @{
  2492. /* Initialize libgfortran. */
  2493. _gfortran_set_args (argc, argv);
  2494. _gfortran_set_record_marker (8);
  2495. return 0;
  2496. @}
  2497. @end smallexample
  2498. @end table
  2499. @node _gfortran_set_fpe
  2500. @subsection @code{_gfortran_set_fpe} --- Enable floating point exception traps
  2501. @fnindex _gfortran_set_fpe
  2502. @cindex libgfortran initialization, set_fpe
  2503. @table @asis
  2504. @item @emph{Description}:
  2505. @code{_gfortran_set_fpe} enables floating point exception traps for
  2506. the specified exceptions. On most systems, this will result in a
  2507. SIGFPE signal being sent and the program being aborted.
  2508. @item @emph{Syntax}:
  2509. @code{void _gfortran_set_fpe (int val)}
  2510. @item @emph{Arguments}:
  2511. @multitable @columnfractions .15 .70
  2512. @item @var{option}[0] @tab IEEE exceptions. Possible values are
  2513. (bitwise or-ed) zero (0, default) no trapping,
  2514. @code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
  2515. @code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
  2516. @code{GFC_FPE_UNDERFLOW} (16), and @code{GFC_FPE_INEXACT} (32).
  2517. @end multitable
  2518. @item @emph{Example}:
  2519. @smallexample
  2520. int main (int argc, char *argv[])
  2521. @{
  2522. /* Initialize libgfortran. */
  2523. _gfortran_set_args (argc, argv);
  2524. /* FPE for invalid operations such as SQRT(-1.0). */
  2525. _gfortran_set_fpe (1);
  2526. return 0;
  2527. @}
  2528. @end smallexample
  2529. @end table
  2530. @node _gfortran_set_max_subrecord_length
  2531. @subsection @code{_gfortran_set_max_subrecord_length} --- Set subrecord length
  2532. @fnindex _gfortran_set_max_subrecord_length
  2533. @cindex libgfortran initialization, set_max_subrecord_length
  2534. @table @asis
  2535. @item @emph{Description}:
  2536. @code{_gfortran_set_max_subrecord_length} set the maximum length
  2537. for a subrecord. This option only makes sense for testing and
  2538. debugging of unformatted I/O.
  2539. @item @emph{Syntax}:
  2540. @code{void _gfortran_set_max_subrecord_length (int val)}
  2541. @item @emph{Arguments}:
  2542. @multitable @columnfractions .15 .70
  2543. @item @var{val} @tab the maximum length for a subrecord;
  2544. the maximum permitted value is 2147483639, which is also
  2545. the default.
  2546. @end multitable
  2547. @item @emph{Example}:
  2548. @smallexample
  2549. int main (int argc, char *argv[])
  2550. @{
  2551. /* Initialize libgfortran. */
  2552. _gfortran_set_args (argc, argv);
  2553. _gfortran_set_max_subrecord_length (8);
  2554. return 0;
  2555. @}
  2556. @end smallexample
  2557. @end table
  2558. @node Naming and argument-passing conventions
  2559. @section Naming and argument-passing conventions
  2560. This section gives an overview about the naming convention of procedures
  2561. and global variables and about the argument passing conventions used by
  2562. GNU Fortran. If a C binding has been specified, the naming convention
  2563. and some of the argument-passing conventions change. If possible,
  2564. mixed-language and mixed-compiler projects should use the better defined
  2565. C binding for interoperability. See @pxref{Interoperability with C}.
  2566. @menu
  2567. * Naming conventions::
  2568. * Argument passing conventions::
  2569. @end menu
  2570. @node Naming conventions
  2571. @subsection Naming conventions
  2572. According the Fortran standard, valid Fortran names consist of a letter
  2573. between @code{A} to @code{Z}, @code{a} to @code{z}, digits @code{0},
  2574. @code{1} to @code{9} and underscores (@code{_}) with the restriction
  2575. that names may only start with a letter. As vendor extension, the
  2576. dollar sign (@code{$}) is additionally permitted with the option
  2577. @option{-fdollar-ok}, but not as first character and only if the
  2578. target system supports it.
  2579. By default, the procedure name is the lower-cased Fortran name with an
  2580. appended underscore (@code{_}); using @option{-fno-underscoring} no
  2581. underscore is appended while @code{-fsecond-underscore} appends two
  2582. underscores. Depending on the target system and the calling convention,
  2583. the procedure might be additionally dressed; for instance, on 32bit
  2584. Windows with @code{stdcall}, an at-sign @code{@@} followed by an integer
  2585. number is appended. For the changing the calling convention, see
  2586. @pxref{GNU Fortran Compiler Directives}.
  2587. For common blocks, the same convention is used, i.e. by default an
  2588. underscore is appended to the lower-cased Fortran name. Blank commons
  2589. have the name @code{__BLNK__}.
  2590. For procedures and variables declared in the specification space of a
  2591. module, the name is formed by @code{__}, followed by the lower-cased
  2592. module name, @code{_MOD_}, and the lower-cased Fortran name. Note that
  2593. no underscore is appended.
  2594. @node Argument passing conventions
  2595. @subsection Argument passing conventions
  2596. Subroutines do not return a value (matching C99's @code{void}) while
  2597. functions either return a value as specified in the platform ABI or
  2598. the result variable is passed as hidden argument to the function and
  2599. no result is returned. A hidden result variable is used when the
  2600. result variable is an array or of type @code{CHARACTER}.
  2601. Arguments are passed according to the platform ABI. In particular,
  2602. complex arguments might not be compatible to a struct with two real
  2603. components for the real and imaginary part. The argument passing
  2604. matches the one of C99's @code{_Complex}. Functions with scalar
  2605. complex result variables return their value and do not use a
  2606. by-reference argument. Note that with the @option{-ff2c} option,
  2607. the argument passing is modified and no longer completely matches
  2608. the platform ABI. Some other Fortran compilers use @code{f2c}
  2609. semantic by default; this might cause problems with
  2610. interoperablility.
  2611. GNU Fortran passes most arguments by reference, i.e. by passing a
  2612. pointer to the data. Note that the compiler might use a temporary
  2613. variable into which the actual argument has been copied, if required
  2614. semantically (copy-in/copy-out).
  2615. For arguments with @code{ALLOCATABLE} and @code{POINTER}
  2616. attribute (including procedure pointers), a pointer to the pointer
  2617. is passed such that the pointer address can be modified in the
  2618. procedure.
  2619. For dummy arguments with the @code{VALUE} attribute: Scalar arguments
  2620. of the type @code{INTEGER}, @code{LOGICAL}, @code{REAL} and
  2621. @code{COMPLEX} are passed by value according to the platform ABI.
  2622. (As vendor extension and not recommended, using @code{%VAL()} in the
  2623. call to a procedure has the same effect.) For @code{TYPE(C_PTR)} and
  2624. procedure pointers, the pointer itself is passed such that it can be
  2625. modified without affecting the caller.
  2626. @c FIXME: Document how VALUE is handled for CHARACTER, TYPE,
  2627. @c CLASS and arrays, i.e. whether the copy-in is done in the caller
  2628. @c or in the callee.
  2629. For Boolean (@code{LOGICAL}) arguments, please note that GCC expects
  2630. only the integer value 0 and 1. If a GNU Fortran @code{LOGICAL}
  2631. variable contains another integer value, the result is undefined.
  2632. As some other Fortran compilers use @math{-1} for @code{.TRUE.},
  2633. extra care has to be taken -- such as passing the value as
  2634. @code{INTEGER}. (The same value restriction also applies to other
  2635. front ends of GCC, e.g. to GCC's C99 compiler for @code{_Bool}
  2636. or GCC's Ada compiler for @code{Boolean}.)
  2637. For arguments of @code{CHARACTER} type, the character length is passed
  2638. as hidden argument. For deferred-length strings, the value is passed
  2639. by reference, otherwise by value. The character length has the type
  2640. @code{INTEGER(kind=4)}. Note with C binding, @code{CHARACTER(len=1)}
  2641. result variables are returned according to the platform ABI and no
  2642. hidden length argument is used for dummy arguments; with @code{VALUE},
  2643. those variables are passed by value.
  2644. For @code{OPTIONAL} dummy arguments, an absent argument is denoted
  2645. by a NULL pointer, except for scalar dummy arguments of type
  2646. @code{INTEGER}, @code{LOGICAL}, @code{REAL} and @code{COMPLEX}
  2647. which have the @code{VALUE} attribute. For those, a hidden Boolean
  2648. argument (@code{logical(kind=C_bool),value}) is used to indicate
  2649. whether the argument is present.
  2650. Arguments which are assumed-shape, assumed-rank or deferred-rank
  2651. arrays or, with @option{-fcoarray=lib}, allocatable scalar coarrays use
  2652. an array descriptor. All other arrays pass the address of the
  2653. first element of the array. With @option{-fcoarray=lib}, the token
  2654. and the offset belonging to nonallocatable coarrays dummy arguments
  2655. are passed as hidden argument along the character length hidden
  2656. arguments. The token is an oparque pointer identifying the coarray
  2657. and the offset is a passed-by-value integer of kind @code{C_PTRDIFF_T},
  2658. denoting the byte offset between the base address of the coarray and
  2659. the passed scalar or first element of the passed array.
  2660. The arguments are passed in the following order
  2661. @itemize @bullet
  2662. @item Result variable, when the function result is passed by reference
  2663. @item Character length of the function result, if it is a of type
  2664. @code{CHARACTER} and no C binding is used
  2665. @item The arguments in the order in which they appear in the Fortran
  2666. declaration
  2667. @item The the present status for optional arguments with value attribute,
  2668. which are internally passed by value
  2669. @item The character length and/or coarray token and offset for the first
  2670. argument which is a @code{CHARACTER} or a nonallocatable coarray dummy
  2671. argument, followed by the hidden arguments of the next dummy argument
  2672. of such a type
  2673. @end itemize
  2674. @c ---------------------------------------------------------------------
  2675. @c Coarray Programming
  2676. @c ---------------------------------------------------------------------
  2677. @node Coarray Programming
  2678. @chapter Coarray Programming
  2679. @cindex Coarrays
  2680. @menu
  2681. * Type and enum ABI Documentation::
  2682. * Function ABI Documentation::
  2683. @end menu
  2684. @node Type and enum ABI Documentation
  2685. @section Type and enum ABI Documentation
  2686. @menu
  2687. * caf_token_t::
  2688. * caf_register_t::
  2689. @end menu
  2690. @node caf_token_t
  2691. @subsection @code{caf_token_t}
  2692. Typedef of type @code{void *} on the compiler side. Can be any data
  2693. type on the library side.
  2694. @node caf_register_t
  2695. @subsection @code{caf_register_t}
  2696. Indicates which kind of coarray variable should be registered.
  2697. @verbatim
  2698. typedef enum caf_register_t {
  2699. CAF_REGTYPE_COARRAY_STATIC,
  2700. CAF_REGTYPE_COARRAY_ALLOC,
  2701. CAF_REGTYPE_LOCK_STATIC,
  2702. CAF_REGTYPE_LOCK_ALLOC,
  2703. CAF_REGTYPE_CRITICAL
  2704. }
  2705. caf_register_t;
  2706. @end verbatim
  2707. @node Function ABI Documentation
  2708. @section Function ABI Documentation
  2709. @menu
  2710. * _gfortran_caf_init:: Initialiation function
  2711. * _gfortran_caf_finish:: Finalization function
  2712. * _gfortran_caf_this_image:: Querying the image number
  2713. * _gfortran_caf_num_images:: Querying the maximal number of images
  2714. * _gfortran_caf_register:: Registering coarrays
  2715. * _gfortran_caf_deregister:: Deregistering coarrays
  2716. * _gfortran_caf_send:: Sending data from a local image to a remote image
  2717. * _gfortran_caf_get:: Getting data from a remote image
  2718. * _gfortran_caf_sendget:: Sending data between remote images
  2719. * _gfortran_caf_lock:: Locking a lock variable
  2720. * _gfortran_caf_unlock:: Unlocking a lock variable
  2721. * _gfortran_caf_sync_all:: All-image barrier
  2722. * _gfortran_caf_sync_images:: Barrier for selected images
  2723. * _gfortran_caf_sync_memory:: Wait for completion of segment-memory operations
  2724. * _gfortran_caf_error_stop:: Error termination with exit code
  2725. * _gfortran_caf_error_stop_str:: Error termination with string
  2726. * _gfortran_caf_atomic_define:: Atomic variable assignment
  2727. * _gfortran_caf_atomic_ref:: Atomic variable reference
  2728. * _gfortran_caf_atomic_cas:: Atomic compare and swap
  2729. * _gfortran_caf_atomic_op:: Atomic operation
  2730. * _gfortran_caf_co_broadcast:: Sending data to all images
  2731. * _gfortran_caf_co_max:: Collective maximum reduction
  2732. * _gfortran_caf_co_min:: Collective minimum reduction
  2733. * _gfortran_caf_co_sum:: Collective summing reduction
  2734. * _gfortran_caf_co_reduce:: Generic collective reduction
  2735. @end menu
  2736. @node _gfortran_caf_init
  2737. @subsection @code{_gfortran_caf_init} --- Initialiation function
  2738. @cindex Coarray, _gfortran_caf_init
  2739. @table @asis
  2740. @item @emph{Description}:
  2741. This function is called at startup of the program before the Fortran main
  2742. program, if the latter has been compiled with @option{-fcoarray=lib}.
  2743. It takes as arguments the command-line arguments of the program. It is
  2744. permitted to pass to @code{NULL} pointers as argument; if non-@code{NULL},
  2745. the library is permitted to modify the arguments.
  2746. @item @emph{Syntax}:
  2747. @code{void _gfortran_caf_init (int *argc, char ***argv)}
  2748. @item @emph{Arguments}:
  2749. @multitable @columnfractions .15 .70
  2750. @item @var{argc} @tab intent(inout) An integer pointer with the number of
  2751. arguments passed to the program or @code{NULL}.
  2752. @item @var{argv} @tab intent(inout) A pointer to an array of strings with the
  2753. command-line arguments or @code{NULL}.
  2754. @end multitable
  2755. @item @emph{NOTES}
  2756. The function is modelled after the initialization function of the Message
  2757. Passing Interface (MPI) specification. Due to the way coarray registration
  2758. works, it might not be the first call to the libaray. If the main program is
  2759. not written in Fortran and only a library uses coarrays, it can happen that
  2760. this function is never called. Therefore, it is recommended that the library
  2761. does not rely on the passed arguments and whether the call has been done.
  2762. @end table
  2763. @node _gfortran_caf_finish
  2764. @subsection @code{_gfortran_caf_finish} --- Finalization function
  2765. @cindex Coarray, _gfortran_caf_finish
  2766. @table @asis
  2767. @item @emph{Description}:
  2768. This function is called at the end of the Fortran main program, if it has
  2769. been compiled with the @option{-fcoarray=lib} option.
  2770. @item @emph{Syntax}:
  2771. @code{void _gfortran_caf_finish (void)}
  2772. @item @emph{NOTES}
  2773. For non-Fortran programs, it is recommended to call the function at the end
  2774. of the main program. To ensure that the shutdown is also performed for
  2775. programs where this function is not explicitly invoked, for instance
  2776. non-Fortran programs or calls to the system's exit() function, the library
  2777. can use a destructor function. Note that programs can also be terminated
  2778. using the STOP and ERROR STOP statements; those use different library calls.
  2779. @end table
  2780. @node _gfortran_caf_this_image
  2781. @subsection @code{_gfortran_caf_this_image} --- Querying the image number
  2782. @cindex Coarray, _gfortran_caf_this_image
  2783. @table @asis
  2784. @item @emph{Description}:
  2785. This function returns the current image number, which is a positive number.
  2786. @item @emph{Syntax}:
  2787. @code{int _gfortran_caf_this_image (int distance)}
  2788. @item @emph{Arguments}:
  2789. @multitable @columnfractions .15 .70
  2790. @item @var{distance} @tab As specified for the @code{this_image} intrinsic
  2791. in TS18508. Shall be a nonnegative number.
  2792. @end multitable
  2793. @item @emph{NOTES}
  2794. If the Fortran intrinsic @code{this_image} is invoked without an argument, which
  2795. is the only permitted form in Fortran 2008, GCC passes @code{0} as
  2796. first argument.
  2797. @end table
  2798. @node _gfortran_caf_num_images
  2799. @subsection @code{_gfortran_caf_num_images} --- Querying the maximal number of images
  2800. @cindex Coarray, _gfortran_caf_num_images
  2801. @table @asis
  2802. @item @emph{Description}:
  2803. This function returns the number of images in the current team, if
  2804. @var{distance} is 0 or the number of images in the parent team at the specified
  2805. distance. If failed is -1, the function returns the number of all images at
  2806. the specified distance; if it is 0, the function returns the number of
  2807. nonfailed images, and if it is 1, it returns the number of failed images.
  2808. @item @emph{Syntax}:
  2809. @code{int _gfortran_caf_num_images(int distance, int failed)}
  2810. @item @emph{Arguments}:
  2811. @multitable @columnfractions .15 .70
  2812. @item @var{distance} @tab the distance from this image to the ancestor.
  2813. Shall be positive.
  2814. @item @var{failed} @tab shall be -1, 0, or 1
  2815. @end multitable
  2816. @item @emph{NOTES}
  2817. This function follows TS18508. If the num_image intrinsic has no arguments,
  2818. the the compiler passes @code{distance=0} and @code{failed=-1} to the function.
  2819. @end table
  2820. @node _gfortran_caf_register
  2821. @subsection @code{_gfortran_caf_register} --- Registering coarrays
  2822. @cindex Coarray, _gfortran_caf_deregister
  2823. @table @asis
  2824. @item @emph{Description}:
  2825. Allocates memory for a coarray and creates a token to identify the coarray. The
  2826. function is called for both coarrays with @code{SAVE} attribute and using an
  2827. explicit @code{ALLOCATE} statement. If an error occurs and @var{STAT} is a
  2828. @code{NULL} pointer, the function shall abort with printing an error message
  2829. and starting the error termination. If no error occurs and @var{STAT} is
  2830. present, it shall be set to zero. Otherwise, it shall be set to a positive
  2831. value and, if not-@code{NULL}, @var{ERRMSG} shall be set to a string describing
  2832. the failure. The function shall return a pointer to the requested memory
  2833. for the local image as a call to @code{malloc} would do.
  2834. For @code{CAF_REGTYPE_COARRAY_STATIC} and @code{CAF_REGTYPE_COARRAY_ALLOC},
  2835. the passed size is the byte size requested. For @code{CAF_REGTYPE_LOCK_STATIC},
  2836. @code{CAF_REGTYPE_LOCK_ALLOC} and @code{CAF_REGTYPE_CRITICAL} it is the array
  2837. size or one for a scalar.
  2838. @item @emph{Syntax}:
  2839. @code{void *caf_register (size_t size, caf_register_t type, caf_token_t *token,
  2840. int *stat, char *errmsg, int errmsg_len)}
  2841. @item @emph{Arguments}:
  2842. @multitable @columnfractions .15 .70
  2843. @item @var{size} @tab For normal coarrays, the byte size of the coarray to be
  2844. allocated; for lock types, the number of elements.
  2845. @item @var{type} @tab one of the caf_register_t types.
  2846. @item @var{token} @tab intent(out) An opaque pointer identifying the coarray.
  2847. @item @var{stat} @tab intent(out) For allocatable coarrays, stores the STAT=;
  2848. may be NULL
  2849. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  2850. an error message; may be NULL
  2851. @item @var{errmsg_len} @tab the buffer size of errmsg.
  2852. @end multitable
  2853. @item @emph{NOTES}
  2854. Nonalloatable coarrays have to be registered prior use from remote images.
  2855. In order to guarantee this, they have to be registered before the main
  2856. program. This can be achieved by creating constructor functions. That is what
  2857. GCC does such that also nonallocatable coarrays the memory is allocated and no
  2858. static memory is used. The token permits to identify the coarray; to the
  2859. processor, the token is a nonaliasing pointer. The library can, for instance,
  2860. store the base address of the coarray in the token, some handle or a more
  2861. complicated struct.
  2862. For normal coarrays, the returned pointer is used for accesses on the local
  2863. image. For lock types, the value shall only used for checking the allocation
  2864. status. Note that for critical blocks, the locking is only required on one
  2865. image; in the locking statement, the processor shall always pass always an
  2866. image index of one for critical-block lock variables
  2867. (@code{CAF_REGTYPE_CRITICAL}).
  2868. @end table
  2869. @node _gfortran_caf_deregister
  2870. @subsection @code{_gfortran_caf_deregister} --- Deregistering coarrays
  2871. @cindex Coarray, _gfortran_caf_deregister
  2872. @table @asis
  2873. @item @emph{Description}:
  2874. Called to free the memory of a coarray; the processor calls this function for
  2875. automatic and explicit deallocation. In case of an error, this function shall
  2876. fail with an error message, unless the @var{STAT} variable is not null.
  2877. @item @emph{Syntax}:
  2878. @code{void caf_deregister (const caf_token_t *token, int *stat, char *errmsg,
  2879. int errmsg_len)}
  2880. @item @emph{Arguments}:
  2881. @multitable @columnfractions .15 .70
  2882. @item @var{stat} @tab intent(out) For allocatable coarrays, stores the STAT=;
  2883. may be NULL
  2884. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set
  2885. to an error message; may be NULL
  2886. @item @var{errmsg_len} @tab the buffer size of errmsg.
  2887. @end multitable
  2888. @item @emph{NOTES}
  2889. For nonalloatable coarrays this function is never called. If a cleanup is
  2890. required, it has to be handled via the finish, stop and error stop functions,
  2891. and via destructors.
  2892. @end table
  2893. @node _gfortran_caf_send
  2894. @subsection @code{_gfortran_caf_send} --- Sending data from a local image to a remote image
  2895. @cindex Coarray, _gfortran_caf_send
  2896. @table @asis
  2897. @item @emph{Description}:
  2898. Called to send a scalar, an array section or whole array from a local
  2899. to a remote image identified by the image_index.
  2900. @item @emph{Syntax}:
  2901. @code{void _gfortran_caf_send (caf_token_t token, size_t offset,
  2902. int image_index, gfc_descriptor_t *dest, caf_vector_t *dst_vector,
  2903. gfc_descriptor_t *src, int dst_kind, int src_kind, bool may_require_tmp)}
  2904. @item @emph{Arguments}:
  2905. @multitable @columnfractions .15 .70
  2906. @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
  2907. @item @var{offset} @tab By which amount of bytes the actual data is shifted
  2908. compared to the base address of the coarray.
  2909. @item @var{image_index} @tab The ID of the remote image; must be a positive
  2910. number.
  2911. @item @var{dest} @tab intent(in) Array descriptor for the remote image for the
  2912. bounds and the size. The base_addr shall not be accessed.
  2913. @item @var{dst_vector} @tab intent(int) If not NULL, it contains the vector
  2914. subscript of the destination array; the values are relative to the dimension
  2915. triplet of the dest argument.
  2916. @item @var{src} @tab intent(in) Array descriptor of the local array to be
  2917. transferred to the remote image
  2918. @item @var{dst_kind} @tab Kind of the destination argument
  2919. @item @var{src_kind} @tab Kind of the source argument
  2920. @item @var{may_require_tmp} @tab The variable is false it is known at compile
  2921. time that the @var{dest} and @var{src} either cannot overlap or overlap (fully
  2922. or partially) such that walking @var{src} and @var{dest} in element wise
  2923. element order (honoring the stride value) will not lead to wrong results.
  2924. Otherwise, the value is true.
  2925. @end multitable
  2926. @item @emph{NOTES}
  2927. It is permitted to have image_id equal the current image; the memory of the
  2928. send-to and the send-from might (partially) overlap in that case. The
  2929. implementation has to take care that it handles this case, e.g. using
  2930. @code{memmove} which handles (partially) overlapping memory. If
  2931. @var{may_require_tmp} is true, the library might additionally create a
  2932. temporary variable, unless additional checks show that this is not required
  2933. (e.g. because walking backward is possible or because both arrays are
  2934. contiguous and @code{memmove} takes care of overlap issues).
  2935. Note that the assignment of a scalar to an array is permitted. In addition,
  2936. the library has to handle numeric-type conversion and for strings, padding
  2937. and different character kinds.
  2938. @end table
  2939. @node _gfortran_caf_get
  2940. @subsection @code{_gfortran_caf_get} --- Getting data from a remote image
  2941. @cindex Coarray, _gfortran_caf_get
  2942. @table @asis
  2943. @item @emph{Description}:
  2944. Called to get an array section or whole array from a a remote,
  2945. image identified by the image_index.
  2946. @item @emph{Syntax}:
  2947. @code{void _gfortran_caf_get_desc (caf_token_t token, size_t offset,
  2948. int image_index, gfc_descriptor_t *src, caf_vector_t *src_vector,
  2949. gfc_descriptor_t *dest, int src_kind, int dst_kind, bool may_require_tmp)}
  2950. @item @emph{Arguments}:
  2951. @multitable @columnfractions .15 .70
  2952. @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
  2953. @item @var{offset} @tab By which amount of bytes the actual data is shifted
  2954. compared to the base address of the coarray.
  2955. @item @var{image_index} @tab The ID of the remote image; must be a positive
  2956. number.
  2957. @item @var{dest} @tab intent(in) Array descriptor of the local array to be
  2958. transferred to the remote image
  2959. @item @var{src} @tab intent(in) Array descriptor for the remote image for the
  2960. bounds and the size. The base_addr shall not be accessed.
  2961. @item @var{src_vector} @tab intent(int) If not NULL, it contains the vector
  2962. subscript of the destination array; the values are relative to the dimension
  2963. triplet of the dest argument.
  2964. @item @var{dst_kind} @tab Kind of the destination argument
  2965. @item @var{src_kind} @tab Kind of the source argument
  2966. @item @var{may_require_tmp} @tab The variable is false it is known at compile
  2967. time that the @var{dest} and @var{src} either cannot overlap or overlap (fully
  2968. or partially) such that walking @var{src} and @var{dest} in element wise
  2969. element order (honoring the stride value) will not lead to wrong results.
  2970. Otherwise, the value is true.
  2971. @end multitable
  2972. @item @emph{NOTES}
  2973. It is permitted to have image_id equal the current image; the memory of the
  2974. send-to and the send-from might (partially) overlap in that case. The
  2975. implementation has to take care that it handles this case, e.g. using
  2976. @code{memmove} which handles (partially) overlapping memory. If
  2977. @var{may_require_tmp} is true, the library might additionally create a
  2978. temporary variable, unless additional checks show that this is not required
  2979. (e.g. because walking backward is possible or because both arrays are
  2980. contiguous and @code{memmove} takes care of overlap issues).
  2981. Note that the library has to handle numeric-type conversion and for strings,
  2982. padding and different character kinds.
  2983. @end table
  2984. @node _gfortran_caf_sendget
  2985. @subsection @code{_gfortran_caf_sendget} --- Sending data between remote images
  2986. @cindex Coarray, _gfortran_caf_sendget
  2987. @table @asis
  2988. @item @emph{Description}:
  2989. Called to send a scalar, an array section or whole array from a remote image
  2990. identified by the src_image_index to a remote image identified by the
  2991. dst_image_index.
  2992. @item @emph{Syntax}:
  2993. @code{void _gfortran_caf_sendget (caf_token_t dst_token, size_t dst_offset,
  2994. int dst_image_index, gfc_descriptor_t *dest, caf_vector_t *dst_vector,
  2995. caf_token_t src_token, size_t src_offset, int src_image_index,
  2996. gfc_descriptor_t *src, caf_vector_t *src_vector, int dst_kind, int src_kind,
  2997. bool may_require_tmp)}
  2998. @item @emph{Arguments}:
  2999. @multitable @columnfractions .15 .70
  3000. @item @var{dst_token} @tab intent(in) An opaque pointer identifying the
  3001. destination coarray.
  3002. @item @var{dst_offset} @tab By which amount of bytes the actual data is
  3003. shifted compared to the base address of the destination coarray.
  3004. @item @var{dst_image_index} @tab The ID of the destination remote image; must
  3005. be a positive number.
  3006. @item @var{dest} @tab intent(in) Array descriptor for the destination
  3007. remote image for the bounds and the size. The base_addr shall not be accessed.
  3008. @item @var{dst_vector} @tab intent(int) If not NULL, it contains the vector
  3009. subscript of the destination array; the values are relative to the dimension
  3010. triplet of the dest argument.
  3011. @item @var{src_token} @tab An opaque pointer identifying the source coarray.
  3012. @item @var{src_offset} @tab By which amount of bytes the actual data is shifted
  3013. compared to the base address of the source coarray.
  3014. @item @var{src_image_index} @tab The ID of the source remote image; must be a
  3015. positive number.
  3016. @item @var{src} @tab intent(in) Array descriptor of the local array to be
  3017. transferred to the remote image.
  3018. @item @var{src_vector} @tab intent(in) Array descriptor of the local array to
  3019. be transferred to the remote image
  3020. @item @var{dst_kind} @tab Kind of the destination argument
  3021. @item @var{src_kind} @tab Kind of the source argument
  3022. @item @var{may_require_tmp} @tab The variable is false it is known at compile
  3023. time that the @var{dest} and @var{src} either cannot overlap or overlap (fully
  3024. or partially) such that walking @var{src} and @var{dest} in element wise
  3025. element order (honoring the stride value) will not lead to wrong results.
  3026. Otherwise, the value is true.
  3027. @end multitable
  3028. @item @emph{NOTES}
  3029. It is permitted to have image_ids equal; the memory of the send-to and the
  3030. send-from might (partially) overlap in that case. The implementation has to
  3031. take care that it handles this case, e.g. using @code{memmove} which handles
  3032. (partially) overlapping memory. If @var{may_require_tmp} is true, the library
  3033. might additionally create a temporary variable, unless additional checks show
  3034. that this is not required (e.g. because walking backward is possible or because
  3035. both arrays are contiguous and @code{memmove} takes care of overlap issues).
  3036. Note that the assignment of a scalar to an array is permitted. In addition,
  3037. the library has to handle numeric-type conversion and for strings, padding and
  3038. different character kinds.
  3039. @end table
  3040. @node _gfortran_caf_lock
  3041. @subsection @code{_gfortran_caf_lock} --- Locking a lock variable
  3042. @cindex Coarray, _gfortran_caf_lock
  3043. @table @asis
  3044. @item @emph{Description}:
  3045. Acquire a lock on the given image on a scalar locking variable or for the
  3046. given array element for an array-valued variable. If the @var{aquired_lock}
  3047. is @code{NULL}, the function return after having obtained the lock. If it is
  3048. nonnull, the result is is assigned the value true (one) when the lock could be
  3049. obtained and false (zero) otherwise. Locking a lock variable which has already
  3050. been locked by the same image is an error.
  3051. @item @emph{Syntax}:
  3052. @code{void _gfortran_caf_lock (caf_token_t token, size_t index, int image_index,
  3053. int *aquired_lock, int *stat, char *errmsg, int errmsg_len)}
  3054. @item @emph{Arguments}:
  3055. @multitable @columnfractions .15 .70
  3056. @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
  3057. @item @var{index} @tab Array index; first array index is 0. For scalars, it is
  3058. always 0.
  3059. @item @var{image_index} @tab The ID of the remote image; must be a positive
  3060. number.
  3061. @item @var{aquired_lock} @tab intent(out) If not NULL, it returns whether lock
  3062. could be obtained
  3063. @item @var{stat} @tab intent(out) For allocatable coarrays, stores the STAT=;
  3064. may be NULL
  3065. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  3066. an error message; may be NULL
  3067. @item @var{errmsg_len} @tab the buffer size of errmsg.
  3068. @end multitable
  3069. @item @emph{NOTES}
  3070. This function is also called for critical blocks; for those, the array index
  3071. is always zero and the image index is one. Libraries are permitted to use other
  3072. images for critical-block locking variables.
  3073. @end table
  3074. @node _gfortran_caf_unlock
  3075. @subsection @code{_gfortran_caf_lock} --- Unlocking a lock variable
  3076. @cindex Coarray, _gfortran_caf_unlock
  3077. @table @asis
  3078. @item @emph{Description}:
  3079. Release a lock on the given image on a scalar locking variable or for the
  3080. given array element for an array-valued variable. Unlocking a lock variable
  3081. which is unlocked or has been locked by a different image is an error.
  3082. @item @emph{Syntax}:
  3083. @code{void _gfortran_caf_unlock (caf_token_t token, size_t index, int image_index,
  3084. int *stat, char *errmsg, int errmsg_len)}
  3085. @item @emph{Arguments}:
  3086. @multitable @columnfractions .15 .70
  3087. @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
  3088. @item @var{index} @tab Array index; first array index is 0. For scalars, it is
  3089. always 0.
  3090. @item @var{image_index} @tab The ID of the remote image; must be a positive
  3091. number.
  3092. @item @var{stat} @tab intent(out) For allocatable coarrays, stores the STAT=;
  3093. may be NULL
  3094. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  3095. an error message; may be NULL
  3096. @item @var{errmsg_len} @tab the buffer size of errmsg.
  3097. @end multitable
  3098. @item @emph{NOTES}
  3099. This function is also called for critical block; for those, the array index
  3100. is always zero and the image index is one. Libraries are permitted to use other
  3101. images for critical-block locking variables.
  3102. @end table
  3103. @node _gfortran_caf_sync_all
  3104. @subsection @code{_gfortran_caf_sync_all} --- All-image barrier
  3105. @cindex Coarray, _gfortran_caf_sync_all
  3106. @table @asis
  3107. @item @emph{Description}:
  3108. Synchronization of all images in the current team; the program only continues
  3109. on a given image after this function has been called on all images of the
  3110. current team. Additionally, it ensures that all pending data transfers of
  3111. previous segment have completed.
  3112. @item @emph{Syntax}:
  3113. @code{void _gfortran_caf_sync_all (int *stat, char *errmsg, int errmsg_len)}
  3114. @item @emph{Arguments}:
  3115. @multitable @columnfractions .15 .70
  3116. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3117. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  3118. an error message; may be NULL
  3119. @item @var{errmsg_len} @tab the buffer size of errmsg.
  3120. @end multitable
  3121. @end table
  3122. @node _gfortran_caf_sync_images
  3123. @subsection @code{_gfortran_caf_sync_images} --- Barrier for selected images
  3124. @cindex Coarray, _gfortran_caf_sync_images
  3125. @table @asis
  3126. @item @emph{Description}:
  3127. Synchronization between the specified images; the program only continues on a
  3128. given image after this function has been called on all images specified for
  3129. that image. Note that one image can wait for all other images in the current
  3130. team (e.g. via @code{sync images(*)}) while those only wait for that specific
  3131. image. Additionally, @code{sync images} it ensures that all pending data
  3132. transfers of previous segment have completed.
  3133. @item @emph{Syntax}:
  3134. @code{void _gfortran_caf_sync_images (int count, int images[], int *stat,
  3135. char *errmsg, int errmsg_len)}
  3136. @item @emph{Arguments}:
  3137. @multitable @columnfractions .15 .70
  3138. @item @var{count} @tab the number of images which are provided in the next
  3139. argument. For a zero-sized array, the value is zero. For @code{sync
  3140. images (*)}, the value is @math{-1}.
  3141. @item @var{images} @tab intent(in) an array with the images provided by the
  3142. user. If @var{count} is zero, a NULL pointer is passed.
  3143. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3144. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  3145. an error message; may be NULL
  3146. @item @var{errmsg_len} @tab the buffer size of errmsg.
  3147. @end multitable
  3148. @end table
  3149. @node _gfortran_caf_sync_memory
  3150. @subsection @code{_gfortran_caf_sync_memory} --- Wait for completion of segment-memory operations
  3151. @cindex Coarray, _gfortran_caf_sync_memory
  3152. @table @asis
  3153. @item @emph{Description}:
  3154. Acts as optimization barrier between different segments. It also ensures that
  3155. all pending memory operations of this image have been completed.
  3156. @item @emph{Syntax}:
  3157. @code{void _gfortran_caf_sync_memory (int *stat, char *errmsg, int errmsg_len)}
  3158. @item @emph{Arguments}:
  3159. @multitable @columnfractions .15 .70
  3160. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3161. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  3162. an error message; may be NULL
  3163. @item @var{errmsg_len} @tab the buffer size of errmsg.
  3164. @end multitable
  3165. @item @emph{NOTE} A simple implementation could be
  3166. @code{__asm__ __volatile__ ("":::"memory")} to prevent code movements.
  3167. @end table
  3168. @node _gfortran_caf_error_stop
  3169. @subsection @code{_gfortran_caf_error_stop} --- Error termination with exit code
  3170. @cindex Coarray, _gfortran_caf_error_stop
  3171. @table @asis
  3172. @item @emph{Description}:
  3173. Invoked for an @code{ERROR STOP} statement which has an integer argument. The
  3174. function should terminate the program with the specified exit code.
  3175. @item @emph{Syntax}:
  3176. @code{void _gfortran_caf_error_stop (int32_t error)}
  3177. @item @emph{Arguments}:
  3178. @multitable @columnfractions .15 .70
  3179. @item @var{error} @tab the exit status to be used.
  3180. @end multitable
  3181. @end table
  3182. @node _gfortran_caf_error_stop_str
  3183. @subsection @code{_gfortran_caf_error_stop_str} --- Error termination with string
  3184. @cindex Coarray, _gfortran_caf_error_stop_str
  3185. @table @asis
  3186. @item @emph{Description}:
  3187. Invoked for an @code{ERROR STOP} statement which has a string as argument. The
  3188. function should terminate the program with a nonzero-exit code.
  3189. @item @emph{Syntax}:
  3190. @code{void _gfortran_caf_error_stop (const char *string, int32_t len)}
  3191. @item @emph{Arguments}:
  3192. @multitable @columnfractions .15 .70
  3193. @item @var{string} @tab the error message (not zero terminated)
  3194. @item @var{len} @tab the length of the string
  3195. @end multitable
  3196. @end table
  3197. @node _gfortran_caf_atomic_define
  3198. @subsection @code{_gfortran_caf_atomic_define} --- Atomic variable assignment
  3199. @cindex Coarray, _gfortran_caf_atomic_define
  3200. @table @asis
  3201. @item @emph{Description}:
  3202. Assign atomically a value to an integer or logical variable.
  3203. @item @emph{Syntax}:
  3204. @code{void _gfortran_caf_atomic_define (caf_token_t token, size_t offset,
  3205. int image_index, void *value, int *stat, int type, int kind)}
  3206. @item @emph{Arguments}:
  3207. @multitable @columnfractions .15 .70
  3208. @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
  3209. @item @var{offset} @tab By which amount of bytes the actual data is shifted
  3210. compared to the base address of the coarray.
  3211. @item @var{image_index} @tab The ID of the remote image; must be a positive
  3212. number.
  3213. @item @var{value} @tab intent(in) the value to be assigned, passed by reference.
  3214. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3215. @item @var{type} @tab the data type, i.e. @code{BT_INTEGER} (1) or
  3216. @code{BT_LOGICAL} (2).
  3217. @item @var{kind} @tab The kind value (only 4; always @code{int})
  3218. @end multitable
  3219. @end table
  3220. @node _gfortran_caf_atomic_ref
  3221. @subsection @code{_gfortran_caf_atomic_ref} --- Atomic variable reference
  3222. @cindex Coarray, _gfortran_caf_atomic_ref
  3223. @table @asis
  3224. @item @emph{Description}:
  3225. Reference atomically a value of a kind-4 integer or logical variable.
  3226. @item @emph{Syntax}:
  3227. @code{void _gfortran_caf_atomic_ref (caf_token_t token, size_t offset,
  3228. int image_index, void *value, int *stat, int type, int kind)}
  3229. @item @emph{Arguments}:
  3230. @item @emph{Arguments}:
  3231. @multitable @columnfractions .15 .70
  3232. @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
  3233. @item @var{offset} @tab By which amount of bytes the actual data is shifted
  3234. compared to the base address of the coarray.
  3235. @item @var{image_index} @tab The ID of the remote image; must be a positive
  3236. number.
  3237. @item @var{value} @tab intent(out) The variable assigned the atomically
  3238. referenced variable.
  3239. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3240. @item @var{type} @tab the data type, i.e. @code{BT_INTEGER} (1) or
  3241. @code{BT_LOGICAL} (2).
  3242. @item @var{kind} @tab The kind value (only 4; always @code{int})
  3243. @end multitable
  3244. @end table
  3245. @node _gfortran_caf_atomic_cas
  3246. @subsection @code{_gfortran_caf_atomic_cas} --- Atomic compare and swap
  3247. @cindex Coarray, _gfortran_caf_atomic_cas
  3248. @table @asis
  3249. @item @emph{Description}:
  3250. Atomic compare and swap of a kind-4 integer or logical variable. Assigns
  3251. atomically the specified value to the atomic variable, if the latter has
  3252. the value specified by the passed condition value.
  3253. @item @emph{Syntax}:
  3254. @code{void _gfortran_caf_atomic_cas (caf_token_t token, size_t offset,
  3255. int image_index, void *old, void *compare, void *new_val, int *stat,
  3256. int type, int kind)}
  3257. @item @emph{Arguments}:
  3258. @multitable @columnfractions .15 .70
  3259. @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
  3260. @item @var{offset} @tab By which amount of bytes the actual data is shifted
  3261. compared to the base address of the coarray.
  3262. @item @var{image_index} @tab The ID of the remote image; must be a positive
  3263. number.
  3264. @item @var{old} @tab intent(out) the value which the atomic variable had
  3265. just before the cas operation.
  3266. @item @var{compare} @tab intent(in) The value used for comparision.
  3267. @item @var{new_val} @tab intent(in) The new value for the atomic variable,
  3268. assigned to the atomic variable, if @code{compare} equals the value of the
  3269. atomic variable.
  3270. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3271. @item @var{type} @tab the data type, i.e. @code{BT_INTEGER} (1) or
  3272. @code{BT_LOGICAL} (2).
  3273. @item @var{kind} @tab The kind value (only 4; always @code{int})
  3274. @end multitable
  3275. @end table
  3276. @node _gfortran_caf_atomic_op
  3277. @subsection @code{_gfortran_caf_atomic_op} --- Atomic operation
  3278. @cindex Coarray, _gfortran_caf_atomic_op
  3279. @table @asis
  3280. @item @emph{Description}:
  3281. Apply an operation atomically to an atomic integer or logical variable.
  3282. After the operation, @var{old} contains the value just before the operation,
  3283. which, respectively, adds (GFC_CAF_ATOMIC_ADD) atomically the @code{value} to
  3284. the atomic integer variable or does a bitwise AND, OR or exclusive OR of the
  3285. between the atomic variable and @var{value}; the result is then stored in the
  3286. atomic variable.
  3287. @item @emph{Syntax}:
  3288. @code{void _gfortran_caf_atomic_op (int op, caf_token_t token, size_t offset,
  3289. int image_index, void *value, void *old, int *stat, int type, int kind)}
  3290. @item @emph{Arguments}:
  3291. @multitable @columnfractions .15 .70
  3292. @item @var{op} @tab the operation to be performed; possible values
  3293. @code{GFC_CAF_ATOMIC_ADD} (1), @code{GFC_CAF_ATOMIC_AND} (2),
  3294. @code{GFC_CAF_ATOMIC_OR} (3), @code{GFC_CAF_ATOMIC_XOR} (4).
  3295. @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
  3296. @item @var{offset} @tab By which amount of bytes the actual data is shifted
  3297. compared to the base address of the coarray.
  3298. @item @var{image_index} @tab The ID of the remote image; must be a positive
  3299. number.
  3300. @item @var{old} @tab intent(out) the value which the atomic variable had
  3301. just before the atomic operation.
  3302. @item @var{val} @tab intent(in) The new value for the atomic variable,
  3303. assigned to the atomic variable, if @code{compare} equals the value of the
  3304. atomic variable.
  3305. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3306. @item @var{type} @tab the data type, i.e. @code{BT_INTEGER} (1) or
  3307. @code{BT_LOGICAL} (2).
  3308. @item @var{kind} @tab The kind value (only 4; always @code{int})
  3309. @end multitable
  3310. @end table
  3311. @node _gfortran_caf_co_broadcast
  3312. @subsection @code{_gfortran_caf_co_broadcast} --- Sending data to all images
  3313. @cindex Coarray, _gfortran_caf_co_broadcast
  3314. @table @asis
  3315. @item @emph{Description}:
  3316. Distribute a value from a given image to all other images in the team. Has to
  3317. be called collectively.
  3318. @item @emph{Syntax}:
  3319. @code{void _gfortran_caf_co_broadcast (gfc_descriptor_t *a,
  3320. int source_image, int *stat, char *errmsg, int errmsg_len)}
  3321. @item @emph{Arguments}:
  3322. @multitable @columnfractions .15 .70
  3323. @item @var{a} @tab intent(inout) And array descriptor with the data to be
  3324. breoadcasted (on @var{source_image}) or to be received (other images).
  3325. @item @var{source_image} @tab The ID of the image from which the data should
  3326. be taken.
  3327. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3328. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  3329. an error message; may be NULL
  3330. @item @var{errmsg_len} @tab the buffer size of errmsg.
  3331. @end multitable
  3332. @end table
  3333. @node _gfortran_caf_co_max
  3334. @subsection @code{_gfortran_caf_co_max} --- Collective maximum reduction
  3335. @cindex Coarray, _gfortran_caf_co_max
  3336. @table @asis
  3337. @item @emph{Description}:
  3338. Calculates the for the each array element of the variable @var{a} the maximum
  3339. value for that element in the current team; if @var{result_image} has the
  3340. value 0, the result shall be stored on all images, otherwise, only on the
  3341. specified image. This function operates on numeric values and character
  3342. strings.
  3343. @item @emph{Syntax}:
  3344. @code{void _gfortran_caf_co_max (gfc_descriptor_t *a, int result_image,
  3345. int *stat, char *errmsg, int a_len, int errmsg_len)}
  3346. @item @emph{Arguments}:
  3347. @multitable @columnfractions .15 .70
  3348. @item @var{a} @tab intent(inout) And array descriptor with the data to be
  3349. breoadcasted (on @var{source_image}) or to be received (other images).
  3350. @item @var{result_image} @tab The ID of the image to which the reduced
  3351. value should be copied to; if zero, it has to be copied to all images.
  3352. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3353. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  3354. an error message; may be NULL
  3355. @item @var{a_len} @tab The string length of argument @var{a}.
  3356. @item @var{errmsg_len} @tab the buffer size of errmsg.
  3357. @end multitable
  3358. @item @emph{NOTES}
  3359. If @var{result_image} is nonzero, the value on all images except of the
  3360. specified one become undefined; hence, the library may make use of this.
  3361. @end table
  3362. @node _gfortran_caf_co_min
  3363. @subsection @code{_gfortran_caf_co_min} --- Collective minimum reduction
  3364. @cindex Coarray, _gfortran_caf_co_min
  3365. @table @asis
  3366. @item @emph{Description}:
  3367. Calculates the for the each array element of the variable @var{a} the minimum
  3368. value for that element in the current team; if @var{result_image} has the
  3369. value 0, the result shall be stored on all images, otherwise, only on the
  3370. specified image. This function operates on numeric values and character
  3371. strings.
  3372. @item @emph{Syntax}:
  3373. @code{void _gfortran_caf_co_min (gfc_descriptor_t *a, int result_image,
  3374. int *stat, char *errmsg, int a_len, int errmsg_len)}
  3375. @item @emph{Arguments}:
  3376. @multitable @columnfractions .15 .70
  3377. @item @var{a} @tab intent(inout) And array descriptor with the data to be
  3378. breoadcasted (on @var{source_image}) or to be received (other images).
  3379. @item @var{result_image} @tab The ID of the image to which the reduced
  3380. value should be copied to; if zero, it has to be copied to all images.
  3381. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3382. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  3383. an error message; may be NULL
  3384. @item @var{a_len} @tab The string length of argument @var{a}.
  3385. @item @var{errmsg_len} @tab the buffer size of errmsg.
  3386. @end multitable
  3387. @item @emph{NOTES}
  3388. If @var{result_image} is nonzero, the value on all images except of the
  3389. specified one become undefined; hence, the library may make use of this.
  3390. @end table
  3391. @node _gfortran_caf_co_sum
  3392. @subsection @code{_gfortran_caf_co_sum} --- Collective summing reduction
  3393. @cindex Coarray, _gfortran_caf_co_sum
  3394. @table @asis
  3395. @item @emph{Description}:
  3396. Calculates the for the each array element of the variable @var{a} the sum
  3397. value for that element in the current team; if @var{result_image} has the
  3398. value 0, the result shall be stored on all images, otherwise, only on the
  3399. specified image. This function operates on numeric values.
  3400. @item @emph{Syntax}:
  3401. @code{void _gfortran_caf_co_sum (gfc_descriptor_t *a, int result_image,
  3402. int *stat, char *errmsg, int errmsg_len)}
  3403. @item @emph{Arguments}:
  3404. @multitable @columnfractions .15 .70
  3405. @item @var{a} @tab intent(inout) And array descriptor with the data to be
  3406. breoadcasted (on @var{source_image}) or to be received (other images).
  3407. @item @var{result_image} @tab The ID of the image to which the reduced
  3408. value should be copied to; if zero, it has to be copied to all images.
  3409. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3410. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  3411. an error message; may be NULL
  3412. @item @var{errmsg_len} @tab the buffer size of errmsg.
  3413. @end multitable
  3414. @item @emph{NOTES}
  3415. If @var{result_image} is nonzero, the value on all images except of the
  3416. specified one become undefined; hence, the library may make use of this.
  3417. @end table
  3418. @node _gfortran_caf_co_reduce
  3419. @subsection @code{_gfortran_caf_co_reduce} --- Generic collective reduction
  3420. @cindex Coarray, _gfortran_caf_co_reduce
  3421. @table @asis
  3422. @item @emph{Description}:
  3423. Calculates the for the each array element of the variable @var{a} the reduction
  3424. value for that element in the current team; if @var{result_image} has the
  3425. value 0, the result shall be stored on all images, otherwise, only on the
  3426. specified image. The @var{opr} is a pure function doing a mathematically
  3427. commutative and associative operation.
  3428. The @var{opr_flags} denote the following; the values are bitwise ored.
  3429. @code{GFC_CAF_BYREF} (1) if the result should be returned
  3430. by value; @code{GFC_CAF_HIDDENLEN} (2) whether the result and argument
  3431. string lengths shall be specified as hidden argument;
  3432. @code{GFC_CAF_ARG_VALUE} (4) whether the arguments shall be passed by value,
  3433. @code{GFC_CAF_ARG_DESC} (8) whether the arguments shall be passed by descriptor.
  3434. @item @emph{Syntax}:
  3435. @code{void _gfortran_caf_co_reduce (gfc_descriptor_t *a,
  3436. void * (*opr) (void *, void *), int opr_flags, int result_image,
  3437. int *stat, char *errmsg, int a_len, int errmsg_len)}
  3438. @item @emph{Arguments}:
  3439. @multitable @columnfractions .15 .70
  3440. @item @var{opr} @tab Function pointer to the reduction function.
  3441. @item @var{opr_flags} @tab Flags regarding the reduction function
  3442. @item @var{a} @tab intent(inout) And array descriptor with the data to be
  3443. breoadcasted (on @var{source_image}) or to be received (other images).
  3444. @item @var{result_image} @tab The ID of the image to which the reduced
  3445. value should be copied to; if zero, it has to be copied to all images.
  3446. @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
  3447. @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
  3448. an error message; may be NULL
  3449. @item @var{a_len} @tab The string length of argument @var{a}.
  3450. @item @var{errmsg_len} @tab the buffer size of errmsg.
  3451. @end multitable
  3452. @item @emph{NOTES}
  3453. If @var{result_image} is nonzero, the value on all images except of the
  3454. specified one become undefined; hence, the library may make use of this.
  3455. For character arguments, the result is passed as first argument, followed
  3456. by the result string length, next come the two string arguments, followed
  3457. by the two hidden arguments. With C binding, there are no hidden arguments
  3458. and by-reference passing and either only a single character is passed or
  3459. an array descriptor.
  3460. @end table
  3461. @c Intrinsic Procedures
  3462. @c ---------------------------------------------------------------------
  3463. @include intrinsic.texi
  3464. @tex
  3465. \blankpart
  3466. @end tex
  3467. @c ---------------------------------------------------------------------
  3468. @c Contributing
  3469. @c ---------------------------------------------------------------------
  3470. @node Contributing
  3471. @unnumbered Contributing
  3472. @cindex Contributing
  3473. Free software is only possible if people contribute to efforts
  3474. to create it.
  3475. We're always in need of more people helping out with ideas
  3476. and comments, writing documentation and contributing code.
  3477. If you want to contribute to GNU Fortran,
  3478. have a look at the long lists of projects you can take on.
  3479. Some of these projects are small,
  3480. some of them are large;
  3481. some are completely orthogonal to the rest of what is
  3482. happening on GNU Fortran,
  3483. but others are ``mainstream'' projects in need of enthusiastic hackers.
  3484. All of these projects are important!
  3485. We will eventually get around to the things here,
  3486. but they are also things doable by someone who is willing and able.
  3487. @menu
  3488. * Contributors::
  3489. * Projects::
  3490. * Proposed Extensions::
  3491. @end menu
  3492. @node Contributors
  3493. @section Contributors to GNU Fortran
  3494. @cindex Contributors
  3495. @cindex Credits
  3496. @cindex Authors
  3497. Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
  3498. also the initiator of the whole project. Thanks Andy!
  3499. Most of the interface with GCC was written by @emph{Paul Brook}.
  3500. The following individuals have contributed code and/or
  3501. ideas and significant help to the GNU Fortran project
  3502. (in alphabetical order):
  3503. @itemize @minus
  3504. @item Janne Blomqvist
  3505. @item Steven Bosscher
  3506. @item Paul Brook
  3507. @item Tobias Burnus
  3508. @item Fran@,{c}ois-Xavier Coudert
  3509. @item Bud Davis
  3510. @item Jerry DeLisle
  3511. @item Erik Edelmann
  3512. @item Bernhard Fischer
  3513. @item Daniel Franke
  3514. @item Richard Guenther
  3515. @item Richard Henderson
  3516. @item Katherine Holcomb
  3517. @item Jakub Jelinek
  3518. @item Niels Kristian Bech Jensen
  3519. @item Steven Johnson
  3520. @item Steven G. Kargl
  3521. @item Thomas Koenig
  3522. @item Asher Langton
  3523. @item H. J. Lu
  3524. @item Toon Moene
  3525. @item Brooks Moses
  3526. @item Andrew Pinski
  3527. @item Tim Prince
  3528. @item Christopher D. Rickett
  3529. @item Richard Sandiford
  3530. @item Tobias Schl@"uter
  3531. @item Roger Sayle
  3532. @item Paul Thomas
  3533. @item Andy Vaught
  3534. @item Feng Wang
  3535. @item Janus Weil
  3536. @item Daniel Kraft
  3537. @end itemize
  3538. The following people have contributed bug reports,
  3539. smaller or larger patches,
  3540. and much needed feedback and encouragement for the
  3541. GNU Fortran project:
  3542. @itemize @minus
  3543. @item Bill Clodius
  3544. @item Dominique d'Humi@`eres
  3545. @item Kate Hedstrom
  3546. @item Erik Schnetter
  3547. @item Joost VandeVondele
  3548. @end itemize
  3549. Many other individuals have helped debug,
  3550. test and improve the GNU Fortran compiler over the past few years,
  3551. and we welcome you to do the same!
  3552. If you already have done so,
  3553. and you would like to see your name listed in the
  3554. list above, please contact us.
  3555. @node Projects
  3556. @section Projects
  3557. @table @emph
  3558. @item Help build the test suite
  3559. Solicit more code for donation to the test suite: the more extensive the
  3560. testsuite, the smaller the risk of breaking things in the future! We can
  3561. keep code private on request.
  3562. @item Bug hunting/squishing
  3563. Find bugs and write more test cases! Test cases are especially very
  3564. welcome, because it allows us to concentrate on fixing bugs instead of
  3565. isolating them. Going through the bugzilla database at
  3566. @url{https://gcc.gnu.org/@/bugzilla/} to reduce testcases posted there and
  3567. add more information (for example, for which version does the testcase
  3568. work, for which versions does it fail?) is also very helpful.
  3569. @end table
  3570. @node Proposed Extensions
  3571. @section Proposed Extensions
  3572. Here's a list of proposed extensions for the GNU Fortran compiler, in no particular
  3573. order. Most of these are necessary to be fully compatible with
  3574. existing Fortran compilers, but they are not part of the official
  3575. J3 Fortran 95 standard.
  3576. @subsection Compiler extensions:
  3577. @itemize @bullet
  3578. @item
  3579. User-specified alignment rules for structures.
  3580. @item
  3581. Automatically extend single precision constants to double.
  3582. @item
  3583. Compile code that conserves memory by dynamically allocating common and
  3584. module storage either on stack or heap.
  3585. @item
  3586. Compile flag to generate code for array conformance checking (suggest -CC).
  3587. @item
  3588. User control of symbol names (underscores, etc).
  3589. @item
  3590. Compile setting for maximum size of stack frame size before spilling
  3591. parts to static or heap.
  3592. @item
  3593. Flag to force local variables into static space.
  3594. @item
  3595. Flag to force local variables onto stack.
  3596. @end itemize
  3597. @subsection Environment Options
  3598. @itemize @bullet
  3599. @item
  3600. Pluggable library modules for random numbers, linear algebra.
  3601. LA should use BLAS calling conventions.
  3602. @item
  3603. Environment variables controlling actions on arithmetic exceptions like
  3604. overflow, underflow, precision loss---Generate NaN, abort, default.
  3605. action.
  3606. @item
  3607. Set precision for fp units that support it (i387).
  3608. @item
  3609. Variable for setting fp rounding mode.
  3610. @item
  3611. Variable to fill uninitialized variables with a user-defined bit
  3612. pattern.
  3613. @item
  3614. Environment variable controlling filename that is opened for that unit
  3615. number.
  3616. @item
  3617. Environment variable to clear/trash memory being freed.
  3618. @item
  3619. Environment variable to control tracing of allocations and frees.
  3620. @item
  3621. Environment variable to display allocated memory at normal program end.
  3622. @item
  3623. Environment variable for filename for * IO-unit.
  3624. @item
  3625. Environment variable for temporary file directory.
  3626. @item
  3627. Environment variable forcing standard output to be line buffered (Unix).
  3628. @end itemize
  3629. @c ---------------------------------------------------------------------
  3630. @c GNU General Public License
  3631. @c ---------------------------------------------------------------------
  3632. @include gpl_v3.texi
  3633. @c ---------------------------------------------------------------------
  3634. @c GNU Free Documentation License
  3635. @c ---------------------------------------------------------------------
  3636. @include fdl.texi
  3637. @c ---------------------------------------------------------------------
  3638. @c Funding Free Software
  3639. @c ---------------------------------------------------------------------
  3640. @include funding.texi
  3641. @c ---------------------------------------------------------------------
  3642. @c Indices
  3643. @c ---------------------------------------------------------------------
  3644. @node Option Index
  3645. @unnumbered Option Index
  3646. @command{gfortran}'s command line options are indexed here without any
  3647. initial @samp{-} or @samp{--}. Where an option has both positive and
  3648. negative forms (such as -foption and -fno-option), relevant entries in
  3649. the manual are indexed under the most appropriate form; it may sometimes
  3650. be useful to look up both forms.
  3651. @printindex op
  3652. @node Keyword Index
  3653. @unnumbered Keyword Index
  3654. @printindex cp
  3655. @bye