Hi
after some searches I have found that from the FILE macro it is possible to extract the filename using the following trick
#define FILENAME (strrchr(FILE , '\') ? strrchr(FILE , '\') + 1 : FILE )
and it works!
Is there anyone out there so kind to explain the magic behind "(strrchr(FILE , '\') ? strrchr(FILE , '\') + 1 : FILE )" ?
Thank you in advance
Dario
gfvalvo
September 29, 2020, 4:36pm
2
The magic comes from the strrchr function .
And, the ternary operator
dariomella:
#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
If
(the address of the last backslash in the filename is not NULL)
?
use the address after the last backslash
: (else)
use the address of the start of the string
1 Like
westfw
October 1, 2020, 5:53am
5
the last backslash
Doesn't sound very OS-independent!
c, file, path, macros