An array is just a pointer

P

Paul

SG said:
Yes. Pointers can be "null" in which case they don't point to
anything.


I did not change my opinion + You think I did = You misunderstood.


You are alone with this view point.
Another incorrect statement confirmed by the person sitting beside me.
 
J

Joshua Maurice

You can't point to a banana in a bunch without also pointing at the bunchof
bananas.

I think you are the one who needs to learn basic English, you're just as bad
as Leigh with your nonsense.

Paul has a small element of truth in what he's been saying, (but still
is largely wrong), so I'm slightly annoyed at this conversation. This
is directed at the people arguing with Paul, as opposed to the troll
himself, to hopefully fix up some vocabulary usage.

Consider:

int* x = new int[10];

The string of characters "x" is an identifier. Almost no one uses that
degree of pedantry though, even the standard. The standard even notes
that it interchangably uses the name of a thing to refer to the name
of the thing, except in specific contexts where the distinction is
important and specifically called out. (What Dan Dennett might call a
"Use Mention Error".)

At a more usable level, x is a variable. It is an object. It has type
"pointer to int". It is a pointer. It is a "pointer to int". Its type
is "a pointer to a (single) int". x is not an array. The type of x is
not an array. The type of x is not pointer to array. No one competent
in C++ would speak otherwise.

At runtime, x holds the address of an int object. Specifically an int
sub-object. x holds the address of the first int element of the heap
array. As such, it's a quite acceptable and understandable looseness
of terms to say "x points at an array". On this point, and only this
point, there is some degree of "rightness" in Paul's arguments ... I
think. Still, in the larger context his speech is too muddled to be
right, or even wrong.

However, no one competent would confuse this for "x has array type",
"x is an array", nor "x has type pointer to array".

Still, saying "x points to an array (object)" is a looseness of terms,
and if asked to clarify what you meant by such a thing, one would
answer "x points to the first element of an array object". This is
similar to saying "x is a pointer", when it fact what you really mean
is "x is an identifier, and the identifier names a pointer object".

Usually conversations such as these are unneeded, except when there's
a dedicated troll who refuses to use the same language of discourse as
overwhelming majority of the rest of the population, in this case
population of C++ programmers.
 
P

Paul

No it's almost the perfect analogy for an array object of subobjects.

"Proof by analogy is fraud."
- Bjarne Stroustrup

Did you really say that?
[...]
Yes; page 692 of TC++PL. A good analogy is an excellent way of
illustrating an idea, but far too often such analogies are not
accompanied by solid reasoning, data, etc.

http://www2.research.att.com/~bs/bs_faq.html
===============================================

Appealing to authority does not decide whether or not the analogy is
accurate.
 
P

Paul

You can't point to a banana in a bunch without also pointing at the bunch
of
bananas.

I think you are the one who needs to learn basic English, you're just as
bad
as Leigh with your nonsense.

Paul has a small element of truth in what he's been saying, (but still
is largely wrong), so I'm slightly annoyed at this conversation. This
is directed at the people arguing with Paul, as opposed to the troll
himself, to hopefully fix up some vocabulary usage.

Consider:

int* x = new int[10];

The string of characters "x" is an identifier. Almost no one uses that
degree of pedantry though, even the standard. The standard even notes
that it interchangably uses the name of a thing to refer to the name
of the thing, except in specific contexts where the distinction is
important and specifically called out. (What Dan Dennett might call a
"Use Mention Error".)

At a more usable level, x is a variable. It is an object. It has type
"pointer to int". It is a pointer. It is a "pointer to int".
No it's a pointer-to... int-type. It's not a pointer to *an* integer, as you
imply , its's a pointer to an array of type int.
For example:
int x=0;
int arr[5]={0};
int* p= &x /*p is pointer to single integer*/
p=arr; /*p is now pointer to an array*/

The same type can be used both as a pointer to an array and as a pointer to
a single integer.
Its type is "a pointer to a (single) int".
No it's not, its type is int*. It's a pointer to an array object of type
int.
x is not an array.
x is a pointer to an array. As you said above: the identifier can refer to
the object it points to interchangeably so x can also be said to be an
array. Just as the following is true:
Animal* p_Cat = new Cat;
p can be said to be a Cat, but it's type is Animal*. We all know it's not
actually a Cat object its a pointer to a Cat object.
The type of x is
not an array.
Correct, it's type is int*.
The type of x is not pointer to array. No one competent
in C++ would speak otherwise.
The type of x is int*. No one competent in C++ would suggest otherwise.
At runtime, x holds the address of an int object. Specifically an int
sub-object. x holds the address of the first int element of the heap
array.
x does not always point to the first element, it can't point to any element
within the array object, or one past.

As such, it's a quite acceptable and understandable looseness
of terms to say "x points at an array".
It's not looseness it's a technical fact that x points to the array object
created by new.
On this point, and only this
point, there is some degree of "rightness" in Paul's arguments ... I
think. Still, in the larger context his speech is too muddled to be
right, or even wrong.

However, no one competent would confuse this for "x has array type",
"x is an array", nor "x has type pointer to array".

Still, saying "x points to an array (object)" is a looseness of terms,
No it's not, it's a technical fact that x points to an array object.
and if asked to clarify what you meant by such a thing, one would
answer "x points to the first element of an array object".

Not always the case , as in the following:
void foo(int s) {
int * p = new int;
/*p doesn't point to any element*/
delete[] p;
}

foo(0);

This is
similar to saying "x is a pointer", when it fact what you really mean
is "x is an identifier, and the identifier names a pointer object".
What you mean is: It's similar to saying x is an array.

Usually conversations such as these are unneeded, except when there's
a dedicated troll who refuses to use the same language of discourse as
overwhelming majority of the rest of the population, in this case

An 1d array of integers is of type int*, a 2d array of integers is of type
int (*)[constant size]. As I demonstrate with the following code:

template<typename T>
void foo(T p){
std::cout<< "\nIn primary foo:\t" << typeid(T).name();
}

template<>
void foo<int*>(int* p){
std::cout<< "\nIn specialized foo:\t" << typeid(p).name();
}

int main(){
const int s = 2;
int arr1[1];
int arr2;
foo(arr1);
foo(arr2);
}

/*Output

In specialized foo: int*
In primary foo: int(*)[2]
end code*/


Stop using bad terminology to misinterpret the language.
If you think I am simply a troll then you know what to do. Please stop
making derogatory comments about me when you do not even know me.

GL.
 
P

Paul

cg_chas said:
No it's almost the perfect analogy for an array object of subobjects.

"Proof by analogy is fraud."
- Bjarne Stroustrup

Did you really say that?
[...]
Yes; page 692 of TC++PL. A good analogy is an excellent way of
illustrating an idea, but far too often such analogies are not
accompanied by solid reasoning, data, etc.

http://www2.research.att.com/~bs/bs_faq.html
===============================================

Appealing to authority does not decide whether or not the analogy is
accurate.

Whether the analogy is accurate or it is not, it is irrelevant because
pointing
to bananas is irrelevant. This is because clear and concise terms useful
for
describing pointers and arrays are widely available for anyone looking to
gain
understanding of these topics. Those interested in doing so are generally
not
looking for new ways too look at old things in a less meaningful context
which
is what your analogy does.

The topics of pointers and arrays has been covered to some degree in most
every
authoritative source of C++ information.

Helping others using experience or authoritative sources is what this
newsgroup
is supposed to be about, but through the use of accurate expression and
appropriate terminology, and in any cases where ambiguity or confusion
arise, we
side on the error of pedantry, or refer to more authoritative sources in
the
appropriate context.

Analogies aside, congruence with an authoritative source is widely
acceptable
for cases where simple terminology, ambiguity, or confusion cannot be
resolved
otherwise.

Anybody who wants to know about pointers and arrays can reference
Stroustrup's
The C++ Programming Language for proper description and explanation.
Or alternatively they could simply compile and run the following code:

template<typename T>
void foo(T p){
std::cout<< "\nIn primary foo:\t" << typeid(T).name();
}

template<>
void foo<int*>(int* p){
std::cout<< "\nIn specialized foo:\t" << typeid(p).name();
}

int main(){
const int s = 2;
int p1[1];
int p2;
foo(p1);
foo(p2);
}

For this particular case, Stroutstup was very clear in his wording with
his
series of examples in TCPPPL 5.3 Pointers into Arrays without being
ambiguous,
or overly pedantic.

int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit conversion)
int* p2 =&v[0]; //pointer to initial element
++p1; //pointer to 2nd element
++p1; //pointer to 3rd element
++p1; //pointer to 4th element
++p1; //pointer to no elements

p1 is a pointer to the array no matter what element it points to.


Paul,

If you do not believe what you read in TCPPPL to be enough pertinent
information
about what a pointer points to, then petition the editor for a text
revision,
but until you have successfully inspired a change with an authoritative
source,
just accept the fact that nobody else here is actually subscribing to your
way
of looking at these topics, and certainly nobody else here agrees with how
you
communicate your points.

The authorative source doesn't disagree with me , you do
..
 
Ö

Öö Tiib

[...]
Consider:

  int* x = new int[10];
[...]

However, no one competent would confuse this for "x has array type",
"x is an array", nor "x has type pointer to array".

Yes but the whole thread is named "array is pointer". That is Paul's
thesis. Rest of it is terribly dim and lacks any logic in most places.

Finger points at first banana in bunch ... so it points at bunch ...
so banana bunch is a finger? I can't imagine how to argue there?
 
J

Joshua Maurice

[...]
Consider:
  int* x = new int[10];
[...]

However, no one competent would confuse this for "x has array type",
"x is an array", nor "x has type pointer to array".

Yes but the whole thread is named "array is pointer". That is Paul's
thesis. Rest of it is terribly dim and lacks any logic in most places.

Of course. In my earlier post, I clearly stated that Paul is not right
on 95%+ of the points which he tries to make, and is frequently not
even wrong due to his unique use of the English language. Still, I was
slightly irritated that no one was willing to give him that for the
code:
int* x = new int[10];
"x points to an array". I know I could easily find myself saying
exactly that.
Finger points at first banana in bunch ... so it points at bunch ...
so banana bunch is a finger? I can't imagine how to argue there?

Nor I, and although I agreed I would keep my Paul feeding to a
minimum, I couldn't help but quote one of my favorite quotes, "proof
by analogy is fraud". That's the short version of the only good
logical reply to such an argument by analogy.
 
S

SG

Or alternatively they could simply compile and run the following code:

template<typename T>
void foo(T p){
  std::cout<< "\nIn primary foo:\t" << typeid(T).name();
}

template<>
void foo<int*>(int* p){
  std::cout<< "\nIn specialized foo:\t" << typeid(p).name();
}

int main(){
  const int s = 2;
  int p1[1];
  int p2;
 foo(p1); // #1
  foo(p2); // #2
}


I guess you intended to prove "an array is just a pointer" again. But
this code example only shows that template argument deduction picks
T=int* respectivly T=int(*)[2]. It does not prove that the arrays
denoted by p1 and p2 are pointers. If you think otherwise, look up the
term "array-to-pointer decay" and check out the template argument
deduction rules in the C++ ISO standard.

BTW: Are you aware of the following?

template<class T>
void foo(T & ref);
:
:
 foo(p1); // --> T = int[1], T& = int(&)[1]
foo(p2); // --> T = int[2][2], T& = int(&)[2][2]

In both cases T& is the type of a reference to an _array_, not a
_pointer_.

SG
 
P

Paul

cg_chas said:
For this particular case, Stroutstup was very clear in his wording with
his
series of examples in TCPPPL 5.3 Pointers into Arrays without being
ambiguous,
or overly pedantic.

int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit conversion)
int* p2 =&v[0]; //pointer to initial element
++p1; //pointer to 2nd element
++p1; //pointer to 3rd element
++p1; //pointer to 4th element
++p1; //pointer to no elements

p1 is a pointer to the array no matter what element it points to.

This statement is even less correct than others that you've made.

Why? becuase you say so?
It's perfectly correct and you don't have the ability to prove otherwise.


The rest of your post just just further proves you don't have a clue about
the C++ langauge.
<snip>
 
P

Paul

[...]
Consider:
int* x = new int[10];
[...]

However, no one competent would confuse this for "x has array type",
"x is an array", nor "x has type pointer to array".

Yes but the whole thread is named "array is pointer". That is Paul's
thesis. Rest of it is terribly dim and lacks any logic in most places.

Of course. In my earlier post, I clearly stated that Paul is not right
on 95%+ of the points which he tries to make, and is frequently not
even wrong due to his unique use of the English language. Still, I was
slightly irritated that no one was willing to give him that for the
code:
int* x = new int[10];
"x points to an array". I know I could easily find myself saying
exactly that.

============================================================
Owned!
 
P

Paul

Or alternatively they could simply compile and run the following code:

template<typename T>
void foo(T p){
std::cout<< "\nIn primary foo:\t" << typeid(T).name();
}

template<>
void foo<int*>(int* p){
std::cout<< "\nIn specialized foo:\t" << typeid(p).name();
}

int main(){
const int s = 2;
int p1[1];
int p2;
foo(p1); // #1
foo(p2); // #2
}


--I guess you intended to prove "an array is just a pointer" again.
-- But

I never have tried to prove this, but nonetheless for all intensive purposes
that's how the language works.

What I have been arguing is againt the idiots who suggest p is not a pointer
to an array, with:
int* p= new int[16];

--this code example only shows that template argument deduction picks
--T=int* respectivly T=int(*)[2]. It does not prove that the arrays
--denoted by p1 and p2 are pointers. If you think otherwise, look up the
--term "array-to-pointer decay" and check out the template argument
--deduction rules in the C++ ISO standard.

--BTW: Are you aware of the following?

-- template<class T>
-- void foo(T & ref);
-- :
-- :
-- foo(p1); // --> T = int[1], T& = int(&)[1]
-- foo(p2); // --> T = int[2][2], T& = int(&)[2][2]

--In both cases T& is the type of a reference to an _array_, not a
--_pointer_.

A reference to an array of int:
int (&r)[5]
is the same type as int* p, not int(*p)[5].

Are you one of those who think p is not a pointer to an array because a
pointer to an array must be type int(*)[SIZE] ?

If you want conclusive proof simply use a specialized traits template:

template<typename T, typename T1>
struct is_same_type{
enum {value = 0};
};
template<typename T>
struct is_same_type<T,T>{
enum {value = 1};
};

template<typename T1, typename T2>
void foo(T1 p1, T2 p2){
if(is_same_type<T1, T2>::value) std::cout<< "Types are the same\n" ;
else std::cout<< "Types are different\n";
}

int main(){
int arr[5]={0};

int* p1 ='\0';
int (*p2)[5] ='\0';
int (&r)[5] = arr;


foo(arr, p1); //Same type
foo(arr, p2); //Different type
foo(arr, r); //Same type
foo( r, p1); //Same type
foo( r, p2); //Different type
}


Tuition fees extra , TYVM and goodbye .
Have a nice day.
 
P

Paul

Leigh Johnston said:
[...]

Consider:

int* x = new int[10];

[...]

However, no one competent would confuse this for "x has array type",
"x is an array", nor "x has type pointer to array".

Yes but the whole thread is named "array is pointer". That is Paul's
thesis. Rest of it is terribly dim and lacks any logic in most places.

Of course. In my earlier post, I clearly stated that Paul is not right
on 95%+ of the points which he tries to make, and is frequently not
even wrong due to his unique use of the English language. Still, I was
slightly irritated that no one was willing to give him that for the
code:
int* x = new int[10];
"x points to an array". I know I could easily find myself saying
exactly that.

============================================================
Owned!

"x points to an array" is different to "x is a pointer to an array"; the
first form is ambiguous but probably OK in informal settings; the second
form is an incorrect description of what "x" is.
Nonsense if x is a pointerto an array then , by defintion, x points to an
array.
*shrug*
 
P

Paul

Leigh Johnston said:
Or alternatively they could simply compile and run the following code:

template<typename T>
void foo(T p){
std::cout<< "\nIn primary foo:\t" << typeid(T).name();
}

template<>
void foo<int*>(int* p){
std::cout<< "\nIn specialized foo:\t" << typeid(p).name();
}

int main(){
const int s = 2;
int p1[1];
int p2;
foo(p1); // #1
foo(p2); // #2
}


--I guess you intended to prove "an array is just a pointer" again.
-- But

I never have tried to prove this, but nonetheless for all intensive
purposes that's how the language works.

What I have been arguing is againt the idiots who suggest p is not a
pointer to an array, with:
int* p= new int[16];

--this code example only shows that template argument deduction picks
--T=int* respectivly T=int(*)[2]. It does not prove that the arrays
--denoted by p1 and p2 are pointers. If you think otherwise, look up the
--term "array-to-pointer decay" and check out the template argument
--deduction rules in the C++ ISO standard.

--BTW: Are you aware of the following?

-- template<class T>
-- void foo(T & ref);
-- :
-- :
-- foo(p1); // --> T = int[1], T& = int(&)[1]
-- foo(p2); // --> T = int[2][2], T& = int(&)[2][2]

--In both cases T& is the type of a reference to an _array_, not a
--_pointer_.

A reference to an array of int:
int (&r)[5]
is the same type as int* p, not int(*p)[5].

Are you one of those who think p is not a pointer to an array because a
pointer to an array must be type int(*)[SIZE] ?

If you want conclusive proof simply use a specialized traits template:

template<typename T, typename T1>
struct is_same_type{
enum {value = 0};
};
template<typename T>
struct is_same_type<T,T>{
enum {value = 1};
};

template<typename T1, typename T2>
void foo(T1 p1, T2 p2){
if(is_same_type<T1, T2>::value) std::cout<< "Types are the same\n" ;
else std::cout<< "Types are different\n";
}

int main(){
int arr[5]={0};

int* p1 ='\0';
int (*p2)[5] ='\0';
int (&r)[5] = arr;


foo(arr, p1); //Same type
foo(arr, p2); //Different type
foo(arr, r); //Same type
foo( r, p1); //Same type
foo( r, p2); //Different type
}


Tuition fees extra , TYVM and goodbye .
Have a nice day.


You have proven nothing:

template<typename T>
void foo(T v)
{
std::cout<< "Not an array\n";
}

v's type could be any type: an array of types, a pointer to an array , or an
array of function pointers.
template <typename T, std::size_t S>
void foo(T (&a))
{
std::cout<< "An array\n";
}

T is an int type.
S is an unsigned int type
a is a reference to an array of type int.

<snip>
 
P

Paul

cg_chas said:
cg_chas said:
For this particular case, Stroutstup was very clear in his wording
with
his
series of examples in TCPPPL 5.3 Pointers into Arrays without being
ambiguous,
or overly pedantic.

int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit conversion)
int* p2 =&v[0]; //pointer to initial element

++p1; //pointer to 2nd element
++p1; //pointer to 3rd element
++p1; //pointer to 4th element
++p1; //pointer to no elements

p1 is a pointer to the array no matter what element it points to.

This statement is even less correct than others that you've made.

Why? becuase you say so?

This isn't about my beliefs or my opinions. I have authoritative sources
that
state the case clearly in favor of my position and not yours.
Please reveal these secret authorative sources that you claim to have.

An expected response..

Your "<snip>" was your only choice because obviously you do not have
anything
concrete to refute the irrefutable.

I snipped because you are simply repeating over and over that you have some
secret authorative source that has yet to be seen.
The burden of proof is on you , you claimed i was incorrect.
 
P

Paul

Leigh Johnston said:
On 21 Mrz., 02:00, Paul wrote:

Or alternatively they could simply compile and run the following code:

template<typename T>
void foo(T p){
std::cout<< "\nIn primary foo:\t" << typeid(T).name();
}

template<>
void foo<int*>(int* p){
std::cout<< "\nIn specialized foo:\t" << typeid(p).name();
}

int main(){
const int s = 2;
int p1[1];
int p2;
foo(p1); // #1
foo(p2); // #2
}

--I guess you intended to prove "an array is just a pointer" again.
-- But

I never have tried to prove this, but nonetheless for all intensive
purposes that's how the language works.

What I have been arguing is againt the idiots who suggest p is not a
pointer to an array, with:
int* p= new int[16];

--this code example only shows that template argument deduction picks
--T=int* respectivly T=int(*)[2]. It does not prove that the arrays
--denoted by p1 and p2 are pointers. If you think otherwise, look up
the
--term "array-to-pointer decay" and check out the template argument
--deduction rules in the C++ ISO standard.

--BTW: Are you aware of the following?

-- template<class T>
-- void foo(T & ref);
-- :
-- :
-- foo(p1); // --> T = int[1], T& = int(&)[1]
-- foo(p2); // --> T = int[2][2], T& = int(&)[2][2]

--In both cases T& is the type of a reference to an _array_, not a
--_pointer_.

A reference to an array of int:
int (&r)[5]
is the same type as int* p, not int(*p)[5].

Are you one of those who think p is not a pointer to an array because a
pointer to an array must be type int(*)[SIZE] ?

If you want conclusive proof simply use a specialized traits template:

template<typename T, typename T1>
struct is_same_type{
enum {value = 0};
};
template<typename T>
struct is_same_type<T,T>{
enum {value = 1};
};

template<typename T1, typename T2>
void foo(T1 p1, T2 p2){
if(is_same_type<T1, T2>::value) std::cout<< "Types are the same\n" ;
else std::cout<< "Types are different\n";
}

int main(){
int arr[5]={0};

int* p1 ='\0';
int (*p2)[5] ='\0';
int (&r)[5] = arr;


foo(arr, p1); //Same type
foo(arr, p2); //Different type
foo(arr, r); //Same type
foo( r, p1); //Same type
foo( r, p2); //Different type
}


Tuition fees extra , TYVM and goodbye .
Have a nice day.


You have proven nothing:

template<typename T>
void foo(T v)
{
std::cout<< "Not an array\n";
}

v's type could be any type: an array of types, a pointer to an array ,
or an array of function pointers.


No it couldn't given the other overload below which will be used for
arrays.

I'm afraid once again I must prove you wrong:

#include <iostream>
template<typename T>
void foo(T v)
{
std::cout<< "\nAn object of type:\t" << typeid(T).name() << " <- Not an
array?\n" ;;
}

template <typename T, std::size_t S>
void foo(T (&a))
{
std::cout<< "\nAn array of type:\t" << typeid(T).name();
}

int main()
{
int arr[6];
int (*parr)[6] = new int[5][6];
foo(arr);
foo(parr);
}


It's about time you learned to accept defeat.
 
P

Paul

Leigh Johnston said:
Leigh Johnston said:
On 21/03/2011 11:58, Paul wrote:


[...]

Consider:

int* x = new int[10];

[...]

However, no one competent would confuse this for "x has array type",
"x is an array", nor "x has type pointer to array".

Yes but the whole thread is named "array is pointer". That is Paul's
thesis. Rest of it is terribly dim and lacks any logic in most places.

Of course. In my earlier post, I clearly stated that Paul is not right
on 95%+ of the points which he tries to make, and is frequently not
even wrong due to his unique use of the English language. Still, I was
slightly irritated that no one was willing to give him that for the
code:
int* x = new int[10];
"x points to an array". I know I could easily find myself saying
exactly that.

============================================================
Owned!


"x points to an array" is different to "x is a pointer to an array";
the first form is ambiguous but probably OK in informal settings; the
second form is an incorrect description of what "x" is.
Nonsense if x is a pointerto an array then , by defintion, x points to
an array.
*shrug*

Correct but that is not what I said. Your comprehension of the English
language and logic is very poor.
Nothing wrong with my English.
You were trying to say : "x points to an array" is OK but "x is a pointer
to the array" is completely wrong. You are speaking complete nonsense
because if one is true the other, by definition, is also true.
 
P

Paul

cg_chas said:
For this particular case, Stroutstup was very clear in his wording
with
his
series of examples in TCPPPL 5.3 Pointers into Arrays without being
ambiguous,
or overly pedantic.

int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit conversion)
int* p2 =&v[0]; //pointer to initial element

++p1; //pointer to 2nd element
++p1; //pointer to 3rd element
++p1; //pointer to 4th element
++p1; //pointer to no elements

p1 is a pointer to the array no matter what element it points to.

This statement is even less correct than others that you've made.

Why? becuase you say so?

This isn't about my beliefs or my opinions. I have authoritative sources
that
state the case clearly in favor of my position and not yours.
Please reveal these secret authorative sources that you claim to have.

I've already revealed them in this very thread. You're just too busy
snipping
and "quickscanning" to use your own wording.
All you posted was the folowing:

<quote ref= "your authorative source">
int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit conversion)
int* p2 =&v[0]; //pointer to initial element
</quote>

In what way do you interpret this to mean that p1 or p2 are not pointers to
an array?


For the sake of your incompetence and apparent incomprehension:

The not-so-secret:
TCPPPL 5.3
Accelerated C++ 10.1.3 and 10.1.5


The burden of proof resides with those (meaning yourself) that oppose
widely
accepted and authoritatve sources such as the two that I have once again
listed
above that tells what a pointer is and what it points to in the context of
an
array.
I'm not opposing anything, I'm just trying to understand how you've
apparently misinterpreted something.
First you say you snipped because I am clueless to the C++ language, now
you say
you snipped because I am quoting sources that I have not shared with you.
You
can continue to change your mind to meet the needs of your argument, but I
will
simply remain consistent and continue to say that you snipped because you
cannot
refute the irrefutable.

No I think I said I snipped because you kept repeating yourself .
You have yet to cite anything authoritative that is congruent with you
position
even a single time, not because you really care about whose burden the
burden of
proof is, but because you cannot refute that the language of the
authoritative
sources is language that has undergone years of revision and scrutiny.
I have given you proof in the form of templated code.

The terminology in TCPPPL and Accelerated C++ is distinct and deliberate.
If
your case bore some form of correctness or pertinance, then your language
would
be what is being used, but it is not.

You can continue to use YOUR own language to describe things, but until
you are
congruent with an authoritative source, then your language is ONLY your
own,
and not that of C++ or even proper English by any international standard.

It's not me that's going against the majority here it's you.
 
P

Paul

Leigh Johnston said:
On 21 Mrz., 02:00, Paul wrote:

Or alternatively they could simply compile and run the following
code:

template<typename T>
void foo(T p){
std::cout<< "\nIn primary foo:\t" << typeid(T).name();
}

template<>
void foo<int*>(int* p){
std::cout<< "\nIn specialized foo:\t" << typeid(p).name();
}

int main(){
const int s = 2;
int p1[1];
int p2;
foo(p1); // #1
foo(p2); // #2
}

--I guess you intended to prove "an array is just a pointer" again.
-- But

I never have tried to prove this, but nonetheless for all intensive
purposes that's how the language works.

What I have been arguing is againt the idiots who suggest p is not a
pointer to an array, with:
int* p= new int[16];

--this code example only shows that template argument deduction picks
--T=int* respectivly T=int(*)[2]. It does not prove that the arrays
--denoted by p1 and p2 are pointers. If you think otherwise, look
up the
--term "array-to-pointer decay" and check out the template argument
--deduction rules in the C++ ISO standard.

--BTW: Are you aware of the following?

-- template<class T>
-- void foo(T & ref);
-- :
-- :
-- foo(p1); // --> T = int[1], T& = int(&)[1]
-- foo(p2); // --> T = int[2][2], T& = int(&)[2][2]

--In both cases T& is the type of a reference to an _array_, not a
--_pointer_.

A reference to an array of int:
int (&r)[5]
is the same type as int* p, not int(*p)[5].

Are you one of those who think p is not a pointer to an array
because a
pointer to an array must be type int(*)[SIZE] ?

If you want conclusive proof simply use a specialized traits
template:

template<typename T, typename T1>
struct is_same_type{
enum {value = 0};
};
template<typename T>
struct is_same_type<T,T>{
enum {value = 1};
};

template<typename T1, typename T2>
void foo(T1 p1, T2 p2){
if(is_same_type<T1, T2>::value) std::cout<< "Types are the same\n" ;
else std::cout<< "Types are different\n";
}

int main(){
int arr[5]={0};

int* p1 ='\0';
int (*p2)[5] ='\0';
int (&r)[5] = arr;


foo(arr, p1); //Same type
foo(arr, p2); //Different type
foo(arr, r); //Same type
foo( r, p1); //Same type
foo( r, p2); //Different type
}


Tuition fees extra , TYVM and goodbye .
Have a nice day.


You have proven nothing:

template<typename T>
void foo(T v)
{
std::cout<< "Not an array\n";
}
v's type could be any type: an array of types, a pointer to an array ,
or an array of function pointers.

No it couldn't given the other overload below which will be used for
arrays.

I'm afraid once again I must prove you wrong:

#include <iostream>
template<typename T>
void foo(T v)
{
std::cout<< "\nAn object of type:\t" << typeid(T).name() << " <- Not an
array?\n" ;;
}

template <typename T, std::size_t S>
void foo(T (&a))
{
std::cout<< "\nAn array of type:\t" << typeid(T).name();
}

int main()
{
int arr[6];
int (*parr)[6] = new int[5][6];
foo(arr);
foo(parr);
}


It's about time you learned to accept defeat.


You fail yet again. A "pointer to an array" is not the same as an
"array".


It's not a pointer to an array though, The object pointed-to is an array of
pointers to arrays (a 2dim array). This is what you do not seem to
understand.
#include <iostream>
template<typename T>
void foo(T v)
{
std::cout<< "\nAn object of type:\t" << typeid(T).name();
}

template <typename T, std::size_t S>
void foo(T (&a))
{
std::cout<< "\nAn array of type:\t" << typeid(T).name();
}

template <typename T, std::size_t S>
void foo(T (*a))
{
std::cout<< "\nA pointer to an array of type:\t" << typeid(T).name();


This is wrong, it produces the output:
"A pointer to an array of type: int" .
The object pointed to is a 2dim array of type int(*).
Your code cannot tell the difference between 1dim arrays and 2dim arrays.
}

int main()
{
int arr[6];
int (*parr)[6] = new int[5][6];
foo(arr);
foo(parr);
}

outputs:

An array of type: int
A pointer to an array of type: int

Learn the basics kid.
Your code and your understanding fails to see why, run the code with
comments and then uncomment the template and run again:

#include <iostream>
template<typename T>
void foo(T v){
std::cout<< "\nfoo 1:\t" << typeid(T).name() << " <- Not an array?\n" ;;
}

template <typename T, std::size_t S>
void foo(T (&a)){
std::cout<< "\nfoo 2:\t" << typeid(T).name();
}

//template <typename T, std::size_t S>
//void foo(T (*a)){
//std::cout<< "\nfoo 3:\t" << typeid(T).name();
//}

template <typename T, std::size_t S1, std::size_t S2>
void foo(T (&a)[S1][S2]){
std::cout<< "\nfoo 4:\t" << typeid(T).name();
}

int main()
{
int (*parr)[6] = new int[5][6];
int p2arr[3][5];
foo(parr);
foo(p2arr);
}


Your understanding of array types is broken and twised. My code is much
better and presents how array types differ in a much better way than yours
does:

template<typename T, typename T1>
struct is_same_type{
enum {value = 0};
};

template<typename T>
struct is_same_type<T,T>{
enum {value = 1};
};

template<typename T, typename U>
void f(T arg1, U arg2){std::cout <<"\nIn Primary: is_same_type:
"<<is_same_type<T,U>::value<< "\ttypeof T: "<<typeid(T).name();}

template<typename T, typename U, typename std::size_t S>
void f(T (&arg1), U* arg2){std::cout <<"\nIn Secondary: is_same_type:
"<<is_same_type<T,U>::value<< "\ttypeof T: "<<typeid(T).name();}

template<typename T, typename U, std::size_t S>
void f(T (*arg1), U (*arg2)){std::cout<<"\nIn secondary: is_same_type:
" <<is_same_type<T,U>::value<< "\ttypeof T: "<<typeid(T).name();}


int main(){
int arr[5];
int (&rarr)[5] = arr;
int* parr = new int[5];
int arr2[7][6];
int (&rarr2)[7][6] = arr2;
int (*parr2)[6] = new int[5][6];

f(rarr, arr);
f(rarr, parr);
f(arr, rarr);
f(arr, parr);
f(parr, arr);
f(parr, rarr);

f(parr, arr2);
f(rarr, arr2);
f(arr, arr2);
f(arr2,parr);
f(arr2,arr);
f(arr2,rarr);

f(arr, parr2);
f(rarr, parr2);
f(parr, parr2);
f(parr2,parr);
f(parr2,arr);
f(parr2,rarr);

f(parr, rarr2);
f(rarr, rarr2);
f(arr, rarr2);
f(rarr2,parr);
f(rarr2,arr);
f(rarr2,rarr);

f(arr2, parr2);
f(arr2, rarr2);
f(rarr2, parr2);
f(rarr2, arr2);
f(parr2, arr2);
f(parr2, rarr2);

//etc etc..
}


My code understands the difference between different array types. And it
doesn't think dynamic arrays are one dimension short of a picnic.
You cannot always retain size info with arrays, you need to accept that
many, if not most, arrays are dynamic.
 
P

Paul

Leigh Johnston said:
Leigh Johnston said:
On 21/03/2011 18:40, Paul wrote:
On 21 Mrz., 02:00, Paul wrote:

Or alternatively they could simply compile and run the following
code:

template<typename T>
void foo(T p){
std::cout<< "\nIn primary foo:\t" << typeid(T).name();
}

template<>
void foo<int*>(int* p){
std::cout<< "\nIn specialized foo:\t" << typeid(p).name();
}

int main(){
const int s = 2;
int p1[1];
int p2;
foo(p1); // #1
foo(p2); // #2
}

--I guess you intended to prove "an array is just a pointer" again.
-- But

I never have tried to prove this, but nonetheless for all intensive
purposes that's how the language works.

What I have been arguing is againt the idiots who suggest p is not
a
pointer to an array, with:
int* p= new int[16];

--this code example only shows that template argument deduction
picks
--T=int* respectivly T=int(*)[2]. It does not prove that the arrays
--denoted by p1 and p2 are pointers. If you think otherwise, look
up the
--term "array-to-pointer decay" and check out the template argument
--deduction rules in the C++ ISO standard.

--BTW: Are you aware of the following?

-- template<class T>
-- void foo(T & ref);
-- :
-- :
-- foo(p1); // --> T = int[1], T& = int(&)[1]
-- foo(p2); // --> T = int[2][2], T& = int(&)[2][2]

--In both cases T& is the type of a reference to an _array_, not a
--_pointer_.

A reference to an array of int:
int (&r)[5]
is the same type as int* p, not int(*p)[5].

Are you one of those who think p is not a pointer to an array
because a
pointer to an array must be type int(*)[SIZE] ?

If you want conclusive proof simply use a specialized traits
template:

template<typename T, typename T1>
struct is_same_type{
enum {value = 0};
};
template<typename T>
struct is_same_type<T,T>{
enum {value = 1};
};

template<typename T1, typename T2>
void foo(T1 p1, T2 p2){
if(is_same_type<T1, T2>::value) std::cout<< "Types are the same\n"
;
else std::cout<< "Types are different\n";
}

int main(){
int arr[5]={0};

int* p1 ='\0';
int (*p2)[5] ='\0';
int (&r)[5] = arr;


foo(arr, p1); //Same type
foo(arr, p2); //Different type
foo(arr, r); //Same type
foo( r, p1); //Same type
foo( r, p2); //Different type
}


Tuition fees extra , TYVM and goodbye .
Have a nice day.


You have proven nothing:

template<typename T>
void foo(T v)
{
std::cout<< "Not an array\n";
}
v's type could be any type: an array of types, a pointer to an array
,
or an array of function pointers.

No it couldn't given the other overload below which will be used for
arrays.

I'm afraid once again I must prove you wrong:

#include <iostream>
template<typename T>
void foo(T v)
{
std::cout<< "\nAn object of type:\t" << typeid(T).name() << " <- Not an
array?\n" ;;
}

template <typename T, std::size_t S>
void foo(T (&a))
{
std::cout<< "\nAn array of type:\t" << typeid(T).name();
}

int main()
{
int arr[6];
int (*parr)[6] = new int[5][6];
foo(arr);
foo(parr);
}


It's about time you learned to accept defeat.

You fail yet again. A "pointer to an array" is not the same as an
"array".


It's not a pointer to an array though, The object pointed-to is an array
of pointers to arrays (a 2dim array). This is what you do not seem to
understand.


No it is not an array of pointers; there is only one pointer namely the
pointer to the array which is itself not an array as it is .. wait for it
.. a pointer. So you fail yet again; you are a lost cause.


Wrong you fail to recognise it's a 2d array , you think its a 1d array.
#include <iostream>
template<typename T>
void foo(T v)
{
std::cout<< "\nAn object of type:\t" << typeid(T).name();
}

template <typename T, std::size_t S>
void foo(T (&a))
{
std::cout<< "\nAn array of type:\t" << typeid(T).name();
}

template <typename T, std::size_t S>
void foo(T (*a))
{
std::cout<< "\nA pointer to an array of type:\t" << typeid(T).name();


This is wrong, it produces the output:
"A pointer to an array of type: int" .
The object pointed to is a 2dim array of type int(*).
Your code cannot tell the difference between 1dim arrays and 2dim arrays.


Wrong again; the third foo will catch pointer to array and the second foo
will catch array. The fact that it prints out the type incorrectly is due
to copy/pasting your code; you are feebly clutching at straws by
highlighting this.


This is your crappy code.
int* p = new int[6];

'p' above is a pointer to an int not a pointer to an array so will be
caught by the first foo.
Bollocks , p points to an array, it can't not be a pointer to an array.

All perfectly fine unlike your understanding of pointer basics.
You dont even understand the simplest basics.
}

int main()
{
int arr[6];
int (*parr)[6] = new int[5][6];
foo(arr);
foo(parr);
}

outputs:

An array of type: int
A pointer to an array of type: int

Learn the basics kid.
Your code and your understanding fails to see why, run the code with
comments and then uncomment the template and run again:

Learn the basics kid.
#include <iostream>
template<typename T>
void foo(T v){
std::cout<< "\nfoo 1:\t" << typeid(T).name() << " <- Not an array?\n" ;;
}

template <typename T, std::size_t S>
void foo(T (&a)){
std::cout<< "\nfoo 2:\t" << typeid(T).name();
}

//template <typename T, std::size_t S>
//void foo(T (*a)){
//std::cout<< "\nfoo 3:\t" << typeid(T).name();
//}

template <typename T, std::size_t S1, std::size_t S2>
void foo(T (&a)[S1][S2]){
std::cout<< "\nfoo 4:\t" << typeid(T).name();
}

int main()
{
int (*parr)[6] = new int[5][6];
int p2arr[3][5];
foo(parr);
foo(p2arr);
}


Your understanding of array types is broken and twised. My code is much
better and presents how array types differ in a much better way than
yours does:


My understanding of arrays is correct; your understanding is what is
warped.

So why do you not only use terminology but you code in such a way that
dynamic arrays are always 1 dimension short of a picnic? to replicate
yourself?
[...]
My code understands the difference between different array types. And it
doesn't think dynamic arrays are one dimension short of a picnic.
You cannot always retain size info with arrays, you need to accept that
many, if not most, arrays are dynamic.

A pointer to an array is not an array. We all know that arrays can decay
to pointers which is all that is happening with your is_same_type
nonsense.
It's not nonsense, its typechecking .
How can a type decay? A type is deduced.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top