digitalmars.D.learn - pointer syntax
- spir (15/15) Oct 29 2010 Hello,
- Simen kjaeraas (8/19) Oct 29 2010 It appears that array structs are automatically created in the data
- bearophile (4/4) Oct 29 2010 I have added your example here:
- spir (8/11) Oct 29 2010 Thank you for your answers. (I'm pleased to see I was not totally stupid...
Hello, I have a little issue with pointer syntax: auto toS =3D &("abc") ; // ok auto toS =3D &"abc" ; // ok auto toI =3D &(1) ; // Error: constant 1 is not an lvalue auto toI =3D &1 ; // Error: constant 1 is not an lvalue The only solution I found is: auto i =3D 1 ; auto toI =3D &i ; It seems to be a pure syntactic problem. But why does it work with strings?= "abc" is no more a lvalue, I guess. Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Oct 29 2010
spir <denis.spir gmail.com> wrote:Hello, I have a little issue with pointer syntax: auto toS = &("abc") ; // ok auto toS = &"abc" ; // ok auto toI = &(1) ; // Error: constant 1 is not an lvalue auto toI = &1 ; // Error: constant 1 is not an lvalue The only solution I found is: auto i = 1 ; auto toI = &i ; It seems to be a pure syntactic problem. But why does it work with strings? "abc" is no more a lvalue, I guess.It appears that array structs are automatically created in the data segment of the executable, and one may thus get a pointer to them. It does make sense to do it this way, but exposing it to let people access it in this way, not so much. I'd say the string example is a bug. -- Simen
Oct 29 2010
I have added your example here: http://d.puremagic.com/issues/show_bug.cgi?id=4539 Bye, bearophile
Oct 29 2010
On Fri, 29 Oct 2010 12:57:39 -0400 bearophile <bearophileHUGS lycos.com> wrote:I have added your example here: =20 http://d.puremagic.com/issues/show_bug.cgi?id=3D4539Thank you for your answers. (I'm pleased to see I was not totally stupid to= find this behaviour somewhat nonsensical ;-) .) Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Oct 29 2010