- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a way to have the preprocessor write __LINE__ inside a string variable directly, as shown below:
S = 'This is line __LINE__'
My tests indicate this does not work; and I have to resort to assigning __LINE__ to an integer variable, then perform an internal write of that variable into a string that I can later concatenate with the rest of my text. I would be curious if there is a workaround.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If there is, I haven't found it myself, and I've tried....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#define THIS_IS_LINE(line_text) 'This is line ' // #line_text #define DESCRIBE_THIS_LINE(the_line) THIS_IS_LINE(the_line) CHARACTER(*), PARAMETER :: s = DESCRIBE_THIS_LINE(__LINE__) PRINT *, s END
>ifort /fpp "2015-01-14 preprocessor.F90" && "2015-01-14 preprocessor.exe" Intel(R) Visual Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.1.148 Build 20141023 Copyright (C) 1985-2014 Intel Corporation. All rights reserved. Microsoft (R) Incremental Linker Version 10.00.40219.01 Copyright (C) Microsoft Corporation. All rights reserved. "-out:2015-01-14 preprocessor.exe" -subsystem:console "2015-01-14 preprocessor.obj" This is line 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IanH's solution has the effect of printing the line number of the declaration of s rather than the line number of the PRINT statement or the line in which s is defined before printing. If the user wants the latter, he/she could use "S = 'This is line' // __LINE__".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks IanH!! Very clever solution - it works perfectly.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page