filename extraction from __FILE__

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

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

Thank you !

the last backslash

Doesn't sound very OS-independent!