Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   PROVEN WRONG! (http://www.velocityreviews.com/forums/t745319-proven-wrong.html)

 Paul 03-18-2011 12:48 AM

PROVEN WRONG!

"Leigh Johnston" <leigh@i42.co.uk> wrote in message
news:WPidnTBFVLvKCh_QnZ2dnUVZ8hydnZ2d@giganews.com ...
> On 17/03/2011 23:00, Paul wrote:
>>

<prune>
>>>>>
>>>>> Maybe the following will help you understand the semantic differences
>>>>> involved:
>>>>>
>>>>> int main()
>>>>> {
>>>>> int* p1 = new int[42]; // 'p1' is a pointer to the first element of an
>>>>> array
>>>>> int (*p2)[42] = new int[1][42]; // 'p2' is a pointer to an array
>>>>> }
>>>>>
>>>> This is a clear indication of how screwed up you are. Please read the
>>>> following :
>>>>
>>>> "the newexpression yields a pointer to the initial element (if any)
>>>> of the
>>>> array. [Note: both new int and new int[10] have type int* and the type
>>>> of new int[i][10] is
>>>> int (*)[10]. ]"
>>>>
>>>>
>>>> The standards define both of these types to be pointers to the array,
>>>> they are just different *types* of pointer.
>>>>
>>>
>>> No; for the final time: int* is not a pointer to an array; int* is a
>>> pointer to a scalar; the Standard clearly states "the new-expression
>>> yields a pointer to the initial element (if any) of the array"; it
>>> doesn't state that "the new-expression yields a pointer to the array".
>>>

>>
>> Err no your nonsense is becoming beyond belief .
>> A pointer to the first element *IS* a pointer to the array.
>>
>> The standards states clearly that both int* and int(*)[10] are pointers
>> to the first element. There is no difference in what these pointers
>> point to. You must think int(*)[10] is an array of pointers or something
>> , *shakes head* no I don't know what nonsense you think.
>>

>
> Yes everything seems like nonsense to you as you are either unable or
> unwilling to be get a firm technical grasp on C++ matters.
>

PROVEN WRONG!

 Paul 03-18-2011 12:49 AM

Re: PROVEN WRONG!

And the idiot is now arguing about what he is wrong about :-S Duh,

 puppi 03-18-2011 10:49 AM

Re: PROVEN WRONG!

On Mar 17, 9:48*pm, "Paul" <pchris...@yahoo.co.uk> wrote:
> "Leigh Johnston" <le...@i42.co.uk> wrote in message
>
> news:WPidnTBFVLvKCh_QnZ2dnUVZ8hydnZ2d@giganews.com ...
>
> > On 17/03/2011 23:00, Paul wrote:

>
> <prune>
>
> >>>>> Maybe the following will help you understand the semantic differences
> >>>>> involved:

>
> >>>>> int main()
> >>>>> {
> >>>>> int* p1 = new int[42]; // 'p1' is a pointer to the first element of an
> >>>>> array
> >>>>> int (*p2)[42] = new int[1][42]; // 'p2' is a pointer to an array
> >>>>> }

>
> >>>> This is a clear indication of how screwed up you are. Please read the
> >>>> following :

>
> >>>> "the newexpression yields a pointer to the initial element (if any)
> >>>> of the
> >>>> array. [Note: both new int and new int[10] have type int* and the type
> >>>> of new int[i][10] is
> >>>> int (*)[10]. ]"

>
> >>>> The standards define both of these types to be pointers to the array,
> >>>> they are just different *types* of pointer.

>
> >>> No; for the final time: int* is not a pointer to an array; int* is a
> >>> pointer to a scalar; the Standard clearly states "the new-expression
> >>> yields a pointer to the initial element (if any) of the array"; it
> >>> doesn't state that "the new-expression yields a pointer to the array"..

>
> >> Err no your nonsense is becoming beyond belief .
> >> A pointer to the first element *IS* a pointer to the array.

>
> >> The standards states clearly that both int* and int(*)[10] are pointers
> >> to the first element. There is no difference in what these pointers
> >> point to. You must think int(*)[10] is an array of pointers or something
> >> , *shakes head* no I don't know what nonsense you think.

>
> > Yes everything seems like nonsense to you as you are either unable or
> > unwilling to be get a firm technical grasp on C++ matters.

>
> PROVEN WRONG!

The only true difference between "int* p1 = new int[42]" and "int (*p2)
[42] = new int[1][42]" is how offsets are computed. ANSI C (and
Standard C++) implement multidimensional arrays as dope vectors, i.e.
as a long linear array with a polynomial evaluation of offsets, which
causes it to act as a multidimensional array. A call such as "new
int[2][42]" would truly return the address of the first element of a
2*42=84 int elements array. They are the same thing at the machine
level. They differ only in how the compiler computes offsets. If n is
an integer type, an expression such as "p1+n" evaluates as the address
in p1 plus n*sizeof(int), while an expression such as "p2+n" evaluates
as the address in p2 plus n*sizeof(int[42]) == 42*n*sizeof(int). An
expression such as "p2[n][m]" evaluates as the address in p2 plus
42*n*sizeof(int)+m*sizeof(int). The following code illustrates that,
where I changed the definition of p2 to "new int[2][42]" for further
explanations:

#include <cstddef>
#include <cassert>

int main()
{
volatile int *p1 = new int[42];
volatile int (*p2)[42] = new int[2][42];

//follow the generated assembly code from here...
asm volatile
(
"nop;\nnop;"
);

p1[2];

asm volatile
(
"nop;\nnop;"
);

p2[0][-1];

asm volatile
(
"nop;\nnop;"
);
//...to here

assert(&p2[1][-1] == &(*p2)[41]);

asm volatile
(
"nop;\nnop;"
);

volatile int *p3 = (int*)p2;

assert(p3+42 == (int*)(p2+1));

for(size_t i = 0; i < 42; i++)
assert(&p3[i] == &p2[0][i]);

for(size_t i = 0; i < 42; i++)
assert(&p3[42+i] == &p2[1][i]);

asm volatile
(
"nop;\nnop;"
);

return 0;
}

If you know your assembly, you should follow how access is made for p1
and p2. You will see it's identical. In my pc generated the following
code fragment for the first part (where p1 was stored in rbp-0x8 and
p2 in rbp-0x10):
movq -8(%rbp), %rax
addq \$8, %rax
movl (%rax), %eax

nop;
nop;

movq -16(%rbp), %rax
movl -4(%rax), %eax
It's simply the same. I declared the pointers volatile simply to
prevent the compiler from "weeding out" parts of my code with no
possible side-effects. Only the line "&p2[1][-1] == &(*p2)[41]" may
not work under all compilers. It will work if and only if
sizeof(size_t)==sizeof(void*).

 Paul 03-18-2011 12:42 PM

Re: PROVEN WRONG!

"puppi" <fabricio.puppi@gmail.com> wrote in message
news:e953b692-324d-42d3-b35c-46ae0824a27c@e9g2000vbk.googlegroups.com...
On Mar 17, 9:48 pm, "Paul" <pchris...@yahoo.co.uk> wrote:
> "Leigh Johnston" <le...@i42.co.uk> wrote in message
>
> news:WPidnTBFVLvKCh_QnZ2dnUVZ8hydnZ2d@giganews.com ...
>
> > On 17/03/2011 23:00, Paul wrote:

>
> <prune>
>
> >>>>> Maybe the following will help you understand the semantic
> >>>>> differences
> >>>>> involved:

>
> >>>>> int main()
> >>>>> {
> >>>>> int* p1 = new int[42]; // 'p1' is a pointer to the first element of
> >>>>> an
> >>>>> array
> >>>>> int (*p2)[42] = new int[1][42]; // 'p2' is a pointer to an array
> >>>>> }

>
> >>>> This is a clear indication of how screwed up you are. Please read the
> >>>> following :

>
> >>>> "the newexpression yields a pointer to the initial element (if any)
> >>>> of the
> >>>> array. [Note: both new int and new int[10] have type int* and the
> >>>> type
> >>>> of new int[i][10] is
> >>>> int (*)[10]. ]"

>
> >>>> The standards define both of these types to be pointers to the array,
> >>>> they are just different *types* of pointer.

>
> >>> No; for the final time: int* is not a pointer to an array; int* is a
> >>> pointer to a scalar; the Standard clearly states "the new-expression
> >>> yields a pointer to the initial element (if any) of the array"; it
> >>> doesn't state that "the new-expression yields a pointer to the array".

>
> >> Err no your nonsense is becoming beyond belief .
> >> A pointer to the first element *IS* a pointer to the array.

>
> >> The standards states clearly that both int* and int(*)[10] are pointers
> >> to the first element. There is no difference in what these pointers
> >> point to. You must think int(*)[10] is an array of pointers or
> >> something
> >> , *shakes head* no I don't know what nonsense you think.

>
> > Yes everything seems like nonsense to you as you are either unable or
> > unwilling to be get a firm technical grasp on C++ matters.

>
> PROVEN WRONG!

The only true difference between "int* p1 = new int[42]" and "int (*p2)
[42] = new int[1][42]" is how offsets are computed. ANSI C (and
Standard C++) implement multidimensional arrays as dope vectors, i.e.
as a long linear array with a polynomial evaluation of offsets, which
causes it to act as a multidimensional array. A call such as "new
int[2][42]" would truly return the address of the first element of a
2*42=84 int elements array. They are the same thing at the machine
level. They differ only in how the compiler computes offsets. If n is
an integer type, an expression such as "p1+n" evaluates as the address
in p1 plus n*sizeof(int), while an expression such as "p2+n" evaluates
as the address in p2 plus n*sizeof(int[42]) == 42*n*sizeof(int). An
expression such as "p2[n][m]" evaluates as the address in p2 plus
42*n*sizeof(int)+m*sizeof(int). The following code illustrates that,
where I changed the definition of p2 to "new int[2][42]" for further
explanations:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

Exactly, the only difference is how the compiler computes the offsets.
And, BTW, nobody in their right mind is ever going to use a type such as
int(*)[64] anyway.

Sorry my auto indentation is not working for this message.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxx

#include <cstddef>
#include <cassert>

int main()
{
volatile int *p1 = new int[42];
volatile int (*p2)[42] = new int[2][42];

//follow the generated assembly code from here...
asm volatile
(
"nop;\nnop;"
);

p1[2];

asm volatile
(
"nop;\nnop;"
);

p2[0][-1];

asm volatile
(
"nop;\nnop;"
);
//...to here

assert(&p2[1][-1] == &(*p2)[41]);

asm volatile
(
"nop;\nnop;"
);

volatile int *p3 = (int*)p2;

assert(p3+42 == (int*)(p2+1));

for(size_t i = 0; i < 42; i++)
assert(&p3[i] == &p2[0][i]);

for(size_t i = 0; i < 42; i++)
assert(&p3[42+i] == &p2[1][i]);

asm volatile
(
"nop;\nnop;"
);

return 0;
}

If you know your assembly, you should follow how access is made for p1
and p2. You will see it's identical. In my pc generated the following
code fragment for the first part (where p1 was stored in rbp-0x8 and
p2 in rbp-0x10):
movq -8(%rbp), %rax
addq \$8, %rax
movl (%rax), %eax

nop;
nop;

movq -16(%rbp), %rax
movl -4(%rax), %eax
It's simply the same. I declared the pointers volatile simply to
prevent the compiler from "weeding out" parts of my code with no
possible side-effects. Only the line "&p2[1][-1] == &(*p2)[41]" may
not work under all compilers. It will work if and only if
sizeof(size_t)==sizeof(void*).

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx

Yes the pointer-type does not affect what it points to in this case. The
only difference is pointer arithmetic in the case of..
int p(*)[size]
1 = sizeof(int) * size.

Not too difficult to understand is it . :)

 Paul 03-18-2011 01:19 PM

Re: PROVEN WRONG!

"Leigh Johnston" <leigh@i42.co.uk> wrote in message
news:Z6mdnbxwZ8Wh0R7QnZ2dnUVZ8mmdnZ2d@giganews.com ...
> On 18/03/2011 10:49, puppi wrote:
>>
>> The only true difference between "int* p1 = new int[42]" and "int (*p2)
>> [42] = new int[1][42]" is how offsets are computed. ANSI C (and

> [...]
>
> As far as the *language* is concerned 'p1' is a pointer to a scalar and
> 'p2' is a pointer to an array; what machine code is actually emitted by a
> particular implementation when using these pointers is irrelevant.
>

Your wording is very err wrong.

p1 is pointer to int *type*.

p2 is pointer to array *type*

Both pointers point to arrays, the difference is dereferenced p1 yields the
an int .

dereferenced p2 yields a pointer to the next dimension of the array. That is
p2 is the same as a pointer to a pointer type.
int* dim2 = p2[2];
std::cout<< dim2[2];

is the same as
std::cout<< p2[2][2];

Its identical to int**.

As far as the language is concerned p1 points to the intial element *of an
array*. The "machine code" isn't irrellevant if it provides a better
understanding of things work.

Note: asm is not machine code. :-S

 Paul 03-18-2011 01:53 PM

Re: PROVEN WRONG!

"Leigh Johnston" <leigh@i42.co.uk> wrote in message
news:XYWdnehl3_Ikwx7QnZ2dnUVZ8nmdnZ2d@giganews.com ...
> On 18/03/2011 13:19, Paul wrote:
>>
>> "Leigh Johnston" <leigh@i42.co.uk> wrote in message
>> news:Z6mdnbxwZ8Wh0R7QnZ2dnUVZ8mmdnZ2d@giganews.com ...
>>> On 18/03/2011 10:49, puppi wrote:
>>>>
>>>> The only true difference between "int* p1 = new int[42]" and "int (*p2)
>>>> [42] = new int[1][42]" is how offsets are computed. ANSI C (and
>>> [...]
>>>
>>> As far as the *language* is concerned 'p1' is a pointer to a scalar
>>> and 'p2' is a pointer to an array; what machine code is actually
>>> emitted by a particular implementation when using these pointers is
>>> irrelevant.
>>>

>> Your wording is very err wrong.
>>
>> p1 is pointer to int *type*.

>
> "int type" is a scalar so my wording is not wrong.

LOL NO its a scalar *TYPE*. Are you a tiotal ****ing idiot altogehter?

>
>>
>> p2 is pointer to array *type*

>

FFS sniop plonk
Idiot.

 Paul 03-18-2011 04:16 PM

Re: PROVEN WRONG!

"Leigh Johnston" <leigh@i42.co.uk> wrote in message
news:mKudnWv0Cfl1-R7QnZ2dnUVZ8n-dnZ2d@giganews.com...
> On 18/03/2011 13:53, Paul wrote:
>>
>> "Leigh Johnston" <leigh@i42.co.uk> wrote in message
>> news:XYWdnehl3_Ikwx7QnZ2dnUVZ8nmdnZ2d@giganews.com ...
>>> On 18/03/2011 13:19, Paul wrote:
>>>>
>>>> "Leigh Johnston" <leigh@i42.co.uk> wrote in message
>>>> news:Z6mdnbxwZ8Wh0R7QnZ2dnUVZ8mmdnZ2d@giganews.com ...
>>>>> On 18/03/2011 10:49, puppi wrote:
>>>>>>
>>>>>> The only true difference between "int* p1 = new int[42]" and "int
>>>>>> (*p2)
>>>>>> [42] = new int[1][42]" is how offsets are computed. ANSI C (and
>>>>> [...]
>>>>>
>>>>> As far as the *language* is concerned 'p1' is a pointer to a scalar
>>>>> and 'p2' is a pointer to an array; what machine code is actually
>>>>> emitted by a particular implementation when using these pointers is
>>>>> irrelevant.
>>>>>
>>>> Your wording is very err wrong.
>>>>
>>>> p1 is pointer to int *type*.
>>>
>>> "int type" is a scalar so my wording is not wrong.

>>
>>
>> LOL NO its a scalar *TYPE*. Are you a tiotal ****ing idiot altogehter?

>
> You are the idiot. Saying "an int type is a scalar" is similar to saying
> "an int type is an int"; both are correct.
>
>>
>>>
>>>>
>>>> p2 is pointer to array *type*
>>>

>> FFS sniop plonk
>> Idiot.

>
> As you show absolutely no willingness to be educated I would be *very*
> happy if you actually meant that plonk.
>

At least I can be educated, you're just presenting totally nonsensical
idioticness all the time.

 Paul 03-18-2011 04:44 PM

Re: PROVEN WRONG!

"Leigh Johnston" <leigh@i42.co.uk> wrote in message
news:ycGdnZ707uakGx7QnZ2dnUVZ8tqdnZ2d@giganews.com ...
> On 18/03/2011 16:16, Paul wrote:
>>
>> "Leigh Johnston" <leigh@i42.co.uk> wrote in message
>> news:mKudnWv0Cfl1-R7QnZ2dnUVZ8n-dnZ2d@giganews.com...
>>> On 18/03/2011 13:53, Paul wrote:
>>>>

<snip>
> I hope you are a troll; I really do; if you aren't a troll and you
> genuinely believe the garbage you post then your situation is probably
> hopeless.
>
> /Leigh
>

Leigh you have nothing sensible to say because I have once again PROVEN YOU
WRONG.
Now why don't you shut up and quietly go away and accept that instead of
behaving like a 6 year old child who had their sweeties taken .

 Paul 03-18-2011 05:06 PM

Re: PROVEN WRONG!

"Leigh Johnston" <leigh@i42.co.uk> wrote in message
news:G_KdnZw_K4wmER7QnZ2dnUVZ8sednZ2d@giganews.com ...
> On 18/03/2011 16:44, Paul wrote:
>>
>> "Leigh Johnston" <leigh@i42.co.uk> wrote in message
>> news:ycGdnZ707uakGx7QnZ2dnUVZ8tqdnZ2d@giganews.com ...
>>> On 18/03/2011 16:16, Paul wrote:
>>>>
>>>> "Leigh Johnston" <leigh@i42.co.uk> wrote in message
>>>> news:mKudnWv0Cfl1-R7QnZ2dnUVZ8n-dnZ2d@giganews.com...
>>>>> On 18/03/2011 13:53, Paul wrote:
>>>>>>

>>
>> <snip>
>>> I hope you are a troll; I really do; if you aren't a troll and you
>>> genuinely believe the garbage you post then your situation is probably
>>> hopeless.
>>>
>>> /Leigh
>>>

>>
>> Leigh you have nothing sensible to say because I have once again PROVEN
>> YOU WRONG.
>> Now why don't you shut up and quietly go away and accept that instead of
>> behaving like a 6 year old child who had their sweeties taken .
>>

>
> The way you repeatedly describe yourself when trying to insult others is
> quite uncanny.
>
>>>>> Maybe the following will help you understand the semantic differences
>>>>> involved:
>>>>>
>>>>> int main()
>>>>> {
>>>>> int* p1 = new int[42]; // 'p1' is a pointer to the first element of an
>>>>> array
>>>>> int (*p2)[42] = new int[1][42]; // 'p2' is a pointer to an array
>>>>> }
>>>>>
>>>> This is a clear indication of how screwed up you are. Please read the
>>>> following :
>>>>
>>>> "the newexpression yields a pointer to the initial element (if any)
>>>> of the
>>>> array. [Note: both new int and new int[10] have type int* and the type
>>>> of new int[i][10] is
>>>> int (*)[10]. ]"
>>>>
>>>>
>>>> The standards define both of these types to be pointers to the array,
>>>> they are just different *types* of pointer.
>>>>

PROVEN WRONG !!
I have nothing more to say , shut up and go away child.

 Noah Roberts 03-18-2011 05:17 PM

Re: PROVEN WRONG!

On 3/18/2011 3:49 AM, puppi wrote:
> On Mar 17, 9:48 pm, "Paul"<pchris...@yahoo.co.uk> wrote:

Holy ****ing christ! Just because this asshole makes yet another new
thread to **** about the same stupid thing doesn't mean people need to
reply.

Is this newsgroup totally dead now? After clearing out the "OMG I got
to prove Paul wrong" bullshit there was only like 3-4 messages of any
interest left.

--
http://crazycpp.wordpress.com

All times are GMT. The time now is 10:57 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.