Is this a bug?

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 28 09:37:52 PDT 2014


On Monday, 28 April 2014 at 14:02:33 UTC, Steven Schveighoffer 
wrote:
> On Mon, 28 Apr 2014 06:04:53 -0400, John Colvin 
> <john.loughran.colvin at gmail.com> wrote:
>
>> On Monday, 28 April 2014 at 09:36:08 UTC, Andrey wrote:
>>>> not a bug.
>>>>
>>>> b.f[10] is indexing the pointer to the array, not the array 
>>>> itself.
>>>>
>>>> b.f[0][10] is indexing the array (with the 10), but I would 
>>>> argue it is better to write *(b.f)[10] so as to be clear 
>>>> that f is not an array.
>>>
>>> thank you, John.
>>>
>>> compiler said that '*(b.f)[10]' is deprecated, and I should 
>>> write like this
>>>
>>> void foo()
>>> {
>>>   Type3 b;
>>>   Type1  d;
>>>   d = *(b.f[10]).ptr;
>>> }
>>
>> struct T
>> {
>> 	int[10]* f;
>> }
>>
>> void main()
>> {
>> 	int[10] test;
>> 	T t = T(&test);
>> 	T* b = &t;
>> 	
>> 	auto d = (*(b.f))[4]; //ugly but clear.
>> 	d = b.f[0][4]; //prettier but less clear.
>> }
>>
>> note the extra brackets on the ugly one, I forgot them before.
>
> You don't need them. (*b.f)[4] works. '.' has precedence over 
> '*'.
>
> -Steve

The extra ones I referred to were the outer ones. Nonetheless, 
you're example is correct.


More information about the Digitalmars-d-learn mailing list