• Re: Is there a way in Fortran to designate an integer value as integer*8 ?

    From Lynn McGuire@lynnmcguire5@gmail.com to comp.lang.fortran on Wed Oct 2 20:12:48 2024
    From Newsgroup: comp.lang.fortran

    On 10/2/2024 5:07 PM, Lawrence D'Oliveiro wrote:
    On Wed, 2 Oct 2024 14:30:48 -0500, Lynn McGuire wrote:

    I will have to put _8 in about 100,000 lines of
    my F77 code.

    There is another way: have a look at the -fdefault-integer-8 and -finteger-4-integer-8 options <https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gfortran/Fortran-Dialect-Options.html>.

    And we have a winner ! Worked like a champ in Simply Fortran.

    Lynn

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From R Daneel Olivaw@Danny@hyperspace.vogon.gov to comp.lang.fortran on Thu Oct 3 14:45:31 2024
    From Newsgroup: comp.lang.fortran

    Lynn McGuire wrote:
    I need many of my integers to be integer*8 in my port to 64 bit.  In
    C/C++ code, I can say 123456L to mean a long long value, generally 64
    bit.  Is there a corresponding way to do this in Fortran or am I stuck with:

        call xyz (1)

        subroutine xyz (ivalue)
        integer*8 ivalue
        ...
        return end

    must be:

        integer*8 ivalue
        ...
        ivalue = 1
        call xyz (ivalue)

    Thanks,
    Lynn


    This is not actually a Fortran issue as such, it's all about a specific compiler (GNU Fortran).
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lawrence D'Oliveiro@ldo@nz.invalid to comp.lang.fortran on Thu Oct 3 22:08:25 2024
    From Newsgroup: comp.lang.fortran

    On Thu, 3 Oct 2024 14:32:28 -0500, Lynn McGuire wrote:

    I have 197 common blocks included from dedicated files and a massive
    number of equivalences all over the place.

    Try getting rid of at least some of them, by using “contains”.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lynn McGuire@lynnmcguire5@gmail.com to comp.lang.fortran on Fri Oct 4 23:10:29 2024
    From Newsgroup: comp.lang.fortran

    On 10/4/2024 12:46 AM, Lawrence D'Oliveiro wrote:
    On Thu, 3 Oct 2024 23:44:24 -0500, Lynn McGuire wrote:

    I started writing Fortran IV in 1975. Been down a lot of roads since
    then. I've written software in Fortran IV and 77, Pascal, C, C++, Curl,
    etc. They are all running together now, I am getting old.

    You mean “Perl” (the language) instead of “Curl” (which is just a download
    tool)?

    No Lisp-type languages? Some of them can do your head in. Assembler? SQL? POSIX shells? JavaScript? My favourite, Python?

    Some cool stuff in modern Fortran: free-form layout, with no more column numbers! Format strings can come from expressions within the I/O
    statement, so there is no more need for statement numbers at all. Types
    can have a limited form of parameterization, even allowing for function overloading. There are structured types, even object orientation.

    Yup, Perl, not Curl. AutoLisp. IBM 370 Assembly. Java. Basic. Lots
    of shell language.

    Yes, I am porting from Open Watcom C++ and F77 to Simply Fortran C++ and GFortran right now. Lots of new stuff that I won't use. Incredibly
    better error detection, especially on variable types and bounds.

    Lynn



    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lynn McGuire@lynnmcguire5@gmail.com to comp.lang.fortran on Sun Oct 20 23:46:40 2024
    From Newsgroup: comp.lang.fortran

    On 10/20/2024 12:38 AM, Lawrence D'Oliveiro wrote:
    On Sat, 5 Oct 2024 15:04:38 -0500, Lynn McGuire wrote:

    On 10/5/2024 1:39 AM, Lawrence D'Oliveiro wrote:

    If I were you, I would look for opportunities to simplify things in
    that Fortran code by using new features, where I have to make major
    modifications to those parts anyway.

    All of the modifications that I am making are minor. Mostly changing my
    old 8 byte data structure/union to I*8 and L*8.

    Here’s another useful thing to do: get rid of COMMON blocks and replace them with MODULE «name» ... USE «name».

    As the compiler does its checking, you may pick up a few long-unnoticed
    typos along the way ...

    I include all of my common blocks as files to stop typos.

    Lynn

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lawrence D'Oliveiro@ldo@nz.invalid to comp.lang.fortran on Wed Oct 23 01:45:17 2024
    From Newsgroup: comp.lang.fortran

    On Tue, 22 Oct 2024 19:42:45 -0500, Lynn McGuire wrote:

    I have "implicit none" in my first mandatory include for all 5,000+ subroutine files.

    “gfortran -fimplicit-none” is also useful.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From antispam@antispam@fricas.org (Waldek Hebisch) to comp.lang.fortran,comp.lang.c on Tue Oct 29 20:04:31 2024
    From Newsgroup: comp.lang.fortran

    In comp.lang.c James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    On 10/27/24 17:01, Lawrence D'Oliveiro wrote:
    On Sun, 27 Oct 2024 08:05:47 -0000 (UTC), Thomas Koenig wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> schrieb:

    On Sat, 26 Oct 2024 21:38:38 -0000 (UTC), Thomas Koenig wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> schrieb:

    On Sat, 26 Oct 2024 11:51:42 -0000 (UTC), Thomas Koenig wrote:

    Lawrence snipped the following extremely relevant text from his
    response, which made it very unclear what the controversy was about.

    #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)."
    [snipped ensuing conversation, which contained nothing of value.]

    It would be more appropriate to cite 6.5.6 itself, rather than Annex J2, which is just a summary. The summary often doesn't go into as much
    detail as the clause being summarized, and the details that are left out
    of the summary are occasionally relevant.
    It would also be better to cite a newer version of the standard. The
    latest I have is n3096, dated 2023-04-01 (but it's not an April Fool's
    joke), and in that version 6.5.6p10 says:

    "If the pointer operand and the result do not point to elements of the
    same array object or one past the last element of the array object, the behavior is undefined."

    However, there was equivalent wording in all previous versions of the C standard, so it doesn't really matter which version you look at.

    As far as C is concerned, whether or not the adjustment had undefined behavior depends entirely upon where i__ points when foo_() is called.
    If it points at any location in an array other than the first element of
    the array (including one past the end of the array), then --i__ is
    perfectly legal, because the result will point at an earlier element of
    the same array. For instance, this would be perfectly legal:

    integer array[11]={0};
    int ret = foo_(array + 1, 10);

    I've seen code like this used to make C code look more like the Fortran
    it was translated from, and in that context a function like this would
    be called with a pointer to the first element of an array, in which case
    the behavior is indeed undefined, which is why that's a bad way to
    handle the translation. But it's the combination of foo_()'s definition,
    and how it is called, that make the behavior undefined, not just the
    code of foo_() itself.

    There is more context to this: AFAICS the relevant use case is
    handling Fortran/f2c calling convention where on entry to the function
    the pointer points to first element of Fortran array. This element
    has index 1 in Fortran but would have index 0 in generated C code.
    f2c wanted to use the same indices as in Fortran, so is doing "adjustment".
    But the resulting base pointer points one element before array,
    so in normal use 6.5.6 applies.

    In effect, in this case Lawrence is making noise but the other
    folks are correct.
    --
    Waldek Hebisch
    --- Synchronet 3.20a-Linux NewsLink 1.114