ROOT Version: 6.20/02
Platform: macOS 10.15.4
Compiler: Clang 11.0.3
Q1. Is there any easy way to suppress the automatic conversion from char* to C string in the example below?
root [0] char str[] {"Hello"}
(char [6]) "Hello"
root [1] *(str + 1)
(char) 'e'
root [2] str + 2
(char *) "llo"
I would like to use the ROOT prompt to educate undergraduate students and to tell them how pointes work in C/C++. In line [2] above, I would like to show the address of str + 2 instead of "loo". The automatic C string conversion in this case is too user friendly for my specific education purpose.
One possible workaround is casting to void*, while at this stage I have not told the students what cast is.
root [3] void* p1 = (void*)str
(void *) 0x1119c0658
root [4] auto p2 = (void*)str
(void *) @0x7ffee1771f18
root [5] p1 == p2
(bool) true
Q2. What is @0x7ffee1771f18 in this example? p1 and p2 are identical when compared with ==, but the two different output 0x1119c0658 and @0x7ffee1771f18 are seen.
Using Form or printf may be another workaround.
root [6] printf("%p", str + 2)
0x1119c065a