# Suppressing automatic string conversion in Cling

**URL:** <https://root-forum.cern.ch/t/suppressing-automatic-string-conversion-in-cling/39212>\
**Category:** ROOT\
**Tags:** cling\
**Created:** [May 2, 2020, 12:44am UTC](https://root-forum.cern.ch/t/suppressing-automatic-string-conversion-in-cling/39212 "2020-05-02T00:44:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![oxon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/oxon/32/12641_2.png) [@oxon](https://root-forum.cern.ch/u/oxon)\
**Post date:** [May 2, 2020, 12:44am UTC](https://root-forum.cern.ch/t/suppressing-automatic-string-conversion-in-cling/39212/1 "2020-05-02T00:44:30Z")

</div>

* * *

_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?

```auto
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.

```auto
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.

```auto
root [6] printf("%p", str + 2)
0x1119c065a

```

---

<div class="post-metadata">

**Author:** ![oshadura](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/oshadura/32/14460_2.png) [@oshadura](https://root-forum.cern.ch/u/oshadura)\
**Post date:** [May 4, 2020, 7:59am UTC](https://root-forum.cern.ch/t/suppressing-automatic-string-conversion-in-cling/39212/2 "2020-05-04T07:59:50Z")

</div>

@Axel @vgvassilev can you please help here? Thanks!

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [May 4, 2020, 5:43pm UTC](https://root-forum.cern.ch/t/suppressing-automatic-string-conversion-in-cling/39212/3 "2020-05-04T17:43:03Z")

</div>

```auto
root [9] void *p = (void*)(str+2)
(void *) 0x105ce20ca

```

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [May 4, 2020, 5:44pm UTC](https://root-forum.cern.ch/t/suppressing-automatic-string-conversion-in-cling/39212/4 "2020-05-04T17:44:12Z")

</div>

> [@oxon](#):
>
> 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.

One if the pointer value while the other is the pointer variable address.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [May 5, 2020, 9:10am UTC](https://root-forum.cern.ch/t/suppressing-automatic-string-conversion-in-cling/39212/5 "2020-05-05T09:10:08Z")

</div>

Q1: I can’t think of a way without a cast, and while keeping them `char*`. `printf` might indeed be the best option.  
Q2: `@` signals that it’s an lvalue, and it shows the address of the lvalue reference - in this case the address of `p2`.

---

<div class="post-metadata">

**Author:** ![oxon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/oxon/32/12641_2.png) [@oxon](https://root-forum.cern.ch/u/oxon)\
**Post date:** [May 5, 2020, 9:32am UTC](https://root-forum.cern.ch/t/suppressing-automatic-string-conversion-in-cling/39212/6 "2020-05-05T09:32:30Z")

</div>

Thank you all.

> in this case the address of `p2` .

I don’t still understand what `@` means.

```auto
root [0] char str[] {"Hello"}
(char [6]) "Hello"
root [1] void* p1 = (void*)str
(void *) 0x10c054658
root [2] auto p2 = (void*)str
(void *) @0x7ffee70ddf28
root [3] &p1
(void **) 0x10c0547a0
root [4] &p2
(void **) 0x10c054880

```

where `p2` points to `0x7ffee70ddf28` but its address is `0x10c054880`.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [May 5, 2020, 10:37am UTC](https://root-forum.cern.ch/t/suppressing-automatic-string-conversion-in-cling/39212/7 "2020-05-05T10:37:25Z")

</div>

Hi Akira!

I think you’re rightfully confused - I believe this is [https://sft.its.cern.ch/jira/browse/ROOT-9687](https://sft.its.cern.ch/jira/browse/ROOT-9687)

Axel

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 19, 2020, 10:38am UTC](https://root-forum.cern.ch/t/suppressing-automatic-string-conversion-in-cling/39212/8 "2020-05-19T10:38:19Z")

</div>

Closed on May 19, 2020, 10:38am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
