www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - pointer syntax

reply spir <denis.spir gmail.com> writes:
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
next sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
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
prev sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
I have added your example here:

http://d.puremagic.com/issues/show_bug.cgi?id=4539

Bye,
bearophile
Oct 29 2010
parent spir <denis.spir gmail.com> writes:
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=3D4539
Thank 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