|
|
Subscribe / Log in / New account

C, Fortran, and single-character strings

C, Fortran, and single-character strings

Posted Jun 20, 2019 22:35 UTC (Thu) by imMute (guest, #96323)
Parent article: C, Fortran, and single-character strings

>it is not a good thing for a compiler update to break code that was working before

I would argue that the code *wasn't* working before...


to post comments

C, Fortran, and single-character strings

Posted Jun 21, 2019 7:19 UTC (Fri) by ibukanov (subscriber, #3942) [Link] (4 responses)

The code wasn't working before in *theory*. In practice it was.

C, Fortran, and single-character strings

Posted Jun 21, 2019 12:35 UTC (Fri) by nivedita76 (subscriber, #121790) [Link] (2 responses)

Just because people were very very lucky. It broke when their luck ran out. Read some of the bug report chains, ALL FORTRAN compilers expect the length argument. Not passing it was probably something one programmer did by mistake once, and it has since been copied around via cargo cult programming techniques. We don’t even know if prior a FORTRAN compilers just by luck never modified that argument for BLAS functions, or if they did but it didn’t kill the program and nobody noticed it.

C, Fortran, and single-character strings

Posted Jun 22, 2019 21:37 UTC (Sat) by ncm (guest, #165) [Link] (1 responses)

Just for now, consider this. The traditional Fortran calling convention is that ALL arguments are passed by reference. To pass a machine-word-sized integer, you pass a pointer. Float, pass a pointer. Double, pass a pointer. In NO case do you push a length after it.

To pass an integer that is to be interpreted as an enumeration value, you also pass just a pointer. In Fortran, enumeration values are conventionally assigned character codes. They're not strings, they're just convenient literal notation for a symbol. Passing a pointer to a character is just the language idiom for an enumerated-value argument.

But passing a pointer to a character is not wrong or fragile code. Changing a library to fail without an extra length argument, after conventional usage is well-established, would be. If, in fact, maintainers of Fortran libraries are doing that, shame on THEM. I see no reason for C users of Fortran libraries to be embarrassed. Their code is not wrong or fragile, absent specific documentation of the original library to the contrary. Changing the compiler to forbid this usage would be wrong.

If you look at the libraries in question, you will probably find places where an argument interpreted as an enumerator is followed by another actual argument, where inserting another, length, argument would produce the wrong result, or a crash.

C, Fortran, and single-character strings

Posted Jun 24, 2019 5:47 UTC (Mon) by joib (subscriber, #8541) [Link]

No, that's not how the Fortran character type works. It's a string with an associated length, not a single char (in C lingo).

C, Fortran, and single-character strings

Posted Jul 7, 2019 1:07 UTC (Sun) by ericharris76 (guest, #132998) [Link]

Maybe a better word to use here is not "working" but "good" or "right".

If the code had no comments and all its variable names were completely arbitrary and the indenting was missing or goofy, it would be "working" but not "right" or "good", even if the calling sequences were all standards-conforming and it always produced the right results, before and after the change to the compiler.

C, Fortran, and single-character strings

Posted Jun 21, 2019 11:22 UTC (Fri) by mb (subscriber, #50428) [Link] (3 responses)

That depends on the definition of "working".
It was working code, if the definition was: "Get the actual job done."
Most people care about getting things done, not about ABI definitions.

C, Fortran, and single-character strings

Posted Jun 21, 2019 12:37 UTC (Fri) by nivedita76 (subscriber, #121790) [Link] (2 responses)

This attitude is exactly what the woodpecker comment is getting at.

C, Fortran, and single-character strings

Posted Jun 22, 2019 10:21 UTC (Sat) by Jandar (subscriber, #85683) [Link]

> This attitude is exactly what the woodpecker comment is getting at.

This attitude is accepting reality and not naming something inconvenient fake facts. If something works than it works - fact. The goal isn't simply to get something to work, it is to get something to work safe and reliable. This distinction between simply working (maybe only backed by luck) and good engineering is the topic of the woodpecker comment.

C, Fortran, and single-character strings

Posted Jun 27, 2019 14:51 UTC (Thu) by jschrod (subscriber, #1646) [Link]

If I look at my 2 houses, the same attitude is used by house builders as well...


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds