- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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.
- Marcas:
- Intel® Fortran Compiler
Link copiado
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
If there is, I haven't found it myself, and I've tried....
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
#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
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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__".
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Thanks IanH!! Very clever solution - it works perfectly.
- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora