Bug 37224 - Request for C string literal syntax
Summary: Request for C string literal syntax
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-24 18:48 UTC by Joe Krahn
Modified: 2008-12-09 22:26 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Krahn 2008-08-24 18:48:36 UTC
Intel Fortran has a notation to specify C string literals by appending the letter C at the end of the string. See here for an example:
http://www.intel.com/software/products/compilers/docs/flin/main_for/mergedProjects/lref_for/source_files/pgcchcs.htm

It would be nice to have this, or something similar, in gfortran.

With Intel Fortran, it causes the string to interpret backslash sequences as in C, and append a NUL character. I suggested to Intel the idea of implementing a .C. unary string operator to do the same thing (I had seen it suggested on c.l.f.), with the idea of trying to fit extensions into vendor intrinsic modules instead of the traditional non-standard syntax approach. They said it would be less standard-conforming, maybe because defined-unary operators cannot be used in initialization expressions. They also stated that the C-suffix approach was a well-establish extension, although neither gfortran nor Sun have it.

I am requesting that gfortran support Intel's C-string notation to improve the portability of C-interop code, if you think the extension is reasonable. It would be nice for Fortran compiler developers to agree on some other common convention, no matter what it is. One negative aspect of Intel's notation is that it would be good to support C escape sequences independent of the NUL terminator.

FYI: I also suggested that they look into gfortran's work on implementing new character kinds such as UTF-8. That will also be very useful for reliable C interop.
Comment 1 Jerry DeLisle 2008-08-24 19:45:36 UTC
gfortran does have -fbackslash that enables c-style interpretation of backslash characters in strings.

With the Intel approach, the code will not compile without error by a standard conforming compiler.  I would not consider that portable at all.

At least with gfortran, the program will compile with or without the -fbackslash.

I am sure there are more portable ways to accomplish these things.
Comment 2 Tobias Burnus 2008-08-24 20:26:02 UTC
> FYI: I also suggested that they look into gfortran's work on implementing new
> character kinds such as UTF-8.

That part is defined in the Fortran 2003 standard (optional) and the almost-ISO-approved Fortran 2008 (mandatory) thus I expect that Intel will get it sooner or later as well.

Regarding the "..."C syntax: I don't quite see why using -fbackslash is not enough plus for zero terminating a string:
   character, parameter :: NUL = achar(0)
then one can use:

  str = "A C-like terminated string"//NUL

which should work with all Fortran compilers. And if one wants to use C escape sequences, one can use the -fbackslash option in gfortran and the -assume bscc option of ifort.

Or one uses instead the predefined values of Fortran 2003 (though their names are a bit long):

"This is followed by a tab"//C_HORIZONTAL_TAB//"*bing*"//C_ALERT//C_NEW_LINE//C_NULL_CHAR

That should also work with all (C-binding supporting) compilers. One could also define shorter names, e.g. C_TAB = C_HORIZONTAL_TAB, C_NL = C_NEW_LINE etc.
Comment 3 Daniel Franke 2008-12-09 22:26:41 UTC
Given comments #1 and #2, this is a WONTFIX. 
Closing. Please reopen if this should be further discussed.