Re: Basic pointer question

2018-02-22 Thread k1attila1
Ok thanks both of you to clarify this problem

Re: Basic pointer question

2018-02-22 Thread Stefan_Salewski
OK, I think I see your problem. In Nim an empty subscript [] notation can be used to derefer a reference or ptr. So if p is a pointer to string, in C++ you would write '*'p to dereference it, but in Nim you write p[]. And in Nim you can write p[n] to access the n'th character in that string. I

Re: Basic pointer question

2018-02-22 Thread mashingan
`p[0]` actually `(p[])[0]` because Nim is smart enough to know `p` is pointer so it lets you get away without deref it.

Re: Basic pointer question

2018-02-22 Thread k1attila1
Thank you and i accept the second part of your answer, BUT the pointer isn't clear yet if you try the given example you see : a[0] ---> 'a' p[0] ---> 'a' too. <\-- why not similar thing like ('*'p)[0] because p and a are different things in GOLANG : > var s string = "alma" > p:= //

Re: Basic pointer question

2018-02-22 Thread Stefan_Salewski
> why not p = a ? Because Nim is statically typed. In your example a is a Nim string, and p a pointer to a Nim string. So data types are different. When you apply addr() to a string, you get a pointer to it. That is similar as it is in C++, where you have C++ strings and can have pointers or

Basic pointer question

2018-02-22 Thread k1attila1
Hello I have tried it : var a = "abc" p: ptr string echo(repr(a)) echo(repr(addr(a))) p = addr(a) #The question : why not p = a ? echo(repr(p)) echo(repr(addr(p))) echo(a[0]) echo(p[0])