|
|
Subscribe / Log in / New account

C, Fortran, and single-character strings

C, Fortran, and single-character strings

Posted Jun 22, 2019 21:37 UTC (Sat) by ncm (guest, #165)
In reply to: C, Fortran, and single-character strings by nivedita76
Parent article: C, Fortran, and single-character strings

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.


to post comments

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).


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