1

I am a little bit puzzled on the INTENT statement of Fortran. I will use a C++-like language to better understand your answers and better express myself.

As far as I understand, there are three possible statements:

  • INTENT(IN) specifies a constant
  • INTENT(OUT) specifies a reference
  • INTENT(INOUT) specifies a local copy which will be copied back

What is the need for distinguishing the last two, OUT and INOUT? Is there some historical limitation that lead to this design?

To clarify: I am not interested in the differences as declared by the standard per se, I need a historical perspective on the introduction of INTENT: why and when, basically.

Thanks & Cheers!

senseiwa
  • 2,369
  • 3
  • 24
  • 47
  • 2
    As a comment: `intent(inout)` isn't the default. Indeed, there is no default. Having no specified `intent` attribute is different from all of those others. – francescalus Jul 16 '15 at 15:58
  • 1
    There are a number of related questions: https://stackoverflow.com/q/29737367, https://stackoverflow.com/q/2880537, https://stackoverflow.com/q/27304084, addressing aspects. – francescalus Jul 16 '15 at 16:00
  • Yes, there are several questions relating to `intent`, however, I'd like to find an historical explanation. I am not interested in the technical modern side, but on when and why they where introduced. – senseiwa Jul 16 '15 at 16:08
  • 1
    @senseiwa That is probably off-topic. Maybe suitable for programmers, I don't know. They were introduced in Fortran 90 after the whole Fortran saga https://www.fortran.com/forsaga.html (long and unpleasant story). But read the other answers it will clear your misconceptions. `intent(inout)` is NOT the default and is not a copy out and in and you can read why in those questions and answers. Using C++ language for Fortran is a VERY bad idea, but ALL of them are like references, but some cons references and some references to a copy. – Vladimir F Героям слава Jul 16 '15 at 16:13
  • 1
    Especially http://stackoverflow.com/questions/29737367/difference-between-intentout-and-intentinout is the one to read and is probably a duplicate. @francescalus could add to his answer that `intent(out)` forces deallocation of any allocatable dummy arguments. – Vladimir F Героям слава Jul 16 '15 at 16:16
  • @VladimirF That's exactly what I'm looking for, and thanks for pointing out the differences with C++. Not easy to find "variable", "intent", or any other reference in the Fortran Saga, but it's a very nice read! Thanks! – senseiwa Jul 16 '15 at 16:17
  • I should have said "possibly" references to a copy. If there will be a copy or not is implementation specific and it is necessary only sometimes. – Vladimir F Героям слава Jul 16 '15 at 16:21
  • I closed it as a duplicate of http://stackoverflow.com/questions/29737367/difference-between-intentout-and-intentinout , francescalus more or less explains how they are different and the need for their introduction follows from that. Comment under his answer for any specific clarifications. – Vladimir F Героям слава Jul 16 '15 at 16:25

0 Answers0