pointer syntax

Simen kjaeraas simen.kjaras at gmail.com
Fri Oct 29 06:00:54 PDT 2010


spir <denis.spir at 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


More information about the Digitalmars-d-learn mailing list