Why do private member variables behaved like protected in the same module when creating deriving class?

Patrick Schluter Patrick.Schluter at bbox.fr
Thu Nov 1 20:47:13 UTC 2018


On Thursday, 1 November 2018 at 19:26:05 UTC, Steven 
Schveighoffer wrote:
> On 11/1/18 2:46 PM, Patrick Schluter wrote:
>> [...]
>
> My testing looks like it's the same:
>
> #include <stdio.h>
> int main()
> {
>     int arr[5];
>     int *ptr = arr + 1; // point at second element so we can do 
> negative indexing legally
>     int idx1 = 0;
>     ptr[--idx1] = 5;
>     printf("%d\n", arr[0]); // 5
>     size_t idx2 = 0;
>     ptr[--idx2] = 6;
>     printf("%d\n", arr[0]); // 6
>     return 0;
> }
>
Compiled with -m64 ? On a 32 bit machine it makes indeed no 
difference as the effective calculated address is in any case 
modulo 2^32-1
(a + 2^32-1) % 2^32 == a-1



More information about the Digitalmars-d mailing list