home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.fortran      Putting John Backus on a giant pedestal      5,127 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 4,808 of 5,127   
   Thomas Koenig to Lynn McGuire   
   Re: Is there a way in Fortran to designa   
   26 Oct 24 11:51:42   
   
   From: tkoenig@netcologne.de   
      
   Lynn McGuire  schrieb:   
   > On 10/24/2024 1:28 AM, Thomas Koenig wrote:   
   >> Lynn McGuire  schrieb:   
      
   >>> F2C fixes the other big problem   
   >>> automatically, the change of initial array index from one to zero.   
   >>   
   >> If I remember correctly, it does so by issueing invalid C (or   
   >> C++), by using negative offsets from pointers.  Might work now,   
   >> might not work tomorrow.   
   >>   
   >> But note the IIRC above.   
   >   
   > I want to move to a monolanguage environment.  50,000 lines of my   
   > calculation engine are C++ already.  850,000 lines to go.   
      
   That motivation, I understand, especially if the GUI code is in C++,   
   but there is a caveat.  Consider   
      
         subroutine foo(i,n)   
         integer array(10)   
         common array   
         integer n   
         integer i(n)   
         integer k   
         do k=1,n   
            i(k) = k + array(k)   
         end do   
         end   
      
   which gets translated by stock f2c (to which you may have made   
   adjustments) into   
      
   #include "f2c.h"   
      
   /* Common Block Declarations */   
      
   struct {   
       integer array[10];   
   } _BLNK__;   
      
   #define _BLNK__1 _BLNK__   
      
   /* Subroutine */ int foo_(integer *i__, integer *n)   
   {   
       /* System generated locals */   
       integer i__1;   
      
       /* Local variables */   
       static integer k;   
      
       /* Parameter adjustments */   
       --i__;   
      
       /* Function Body */   
       i__1 = *n;   
       for (k = 1; k <= i__1; ++k) {   
   	i__[k] = k + _BLNK__1.array[k - 1];   
       }   
       return 0;   
   } /* foo_ */   
      
   The common block handling looks OK, but the dummy argument   
   (aka parameters, in C parlance) handling is very probably not.   
      
   The "parameter adjustment" above is explicitly listed as undefined   
   behavior, in annex J2 of n2596.pdf (for example):   
      
   "Addition or subtraction of a pointer into, or just beyond, an   
   array object and an integer type produces a result that does not   
   point into, or just beyond, the same array object (6.5.6)."   
      
   Undefined behavior is the worst kind of error in your program   
   that you can have in C, it is not required to be diagnosed, and   
   compilers can, and do, make optimizations based on the assumption   
   that it does not happen, so this is liable to break in unforseen   
   circumstances.   
      
   So if your version of f2c does the same, I would check the C++   
   standard if if has a similar provision (I strongly suspect so,   
   but I don't know), and, if that is the case, modify your version   
   of f2c to generate conforming code for array dummy arguments.   
   Otherwise, you are betting your company.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca