H
hpsoar
int array[] = {1, 2, 3};
then what is the type of &array? Is it int**, or some other type?
then what is the type of &array? Is it int**, or some other type?
hpsoar said:int array[] = {1, 2, 3};
then what is the type of &array? Is it int**, or some other type?
WANG said:hpsoar said:int array[] = {1, 2, 3};
then what is the type of &array? Is it int**, or some other type?
It should be int* instead of int **, because an array name is _not_
a pointer.
Kai-Uwe Bux said:You might want to test that hypothesis:
The term »pointer« is not explicitly defined by ISO/IEC 14882:2003(E).
Stefan said:The term »pointer« is not explicitly defined by ISO/IEC 14882:2003(E).
I would suggest the natural definition:
»A pointer is a value of a pointer type.«
It seems also safe to assume that
»an array name is a name.«
A name is not a value, these two entities even belong to different
models:
A name is an entity of the source-code model.
A value (a pointer) is an entity of the run-time model.
So an array name cannot be a pointer.
This assertion can not be tested by running code on programs
that claim to be implementations of ISO/IEC 14882:2003(E), it
needs to be deduced from ISO/IEC 14882:2003(E) and reasonable
assumptions.
int array[] = {1, 2, 3};
then what is the type of &array? Is it int**, or some other type?
It should be int* instead of int **, because ...
Kai-Uwe Bux said:WANG said:hpsoar said:int array[] = {1, 2, 3};
then what is the type of &array? Is it int**, or some other type?
It should be int* instead of int **, because an array name is _not_
a pointer.
You might want to test that hypothesis:
Stefan said:I found this:
»pointer - an object holding an address or 0.«
http://www.research.att.com/~bs/glossary.html
I have heard such a claim several times, but object to it,
because by this, for example, »&i« for an int variable »i«
would not be a pointer, because »&i« is not an object. But
I believe everyone wants »&i« to be a pointer.
int array[] = {1, 2, 3};
then what is the type of &array? Is it int**, or some other type?
Stefan said:I found this:
»pointer - an object holding an address or 0.«
http://www.research.att.com/~bs/glossary.html
I have heard such a claim several times, but object to it,
because by this, for example, »&i« for an int variable »i«
would not be a pointer, because »&i« is not an object. But
I believe everyone wants »&i« to be a pointer.
Kai-Uwe Bux said:WANG Cong wrote:You might want to test that hypothesis:hpsoar wrote:
int array[] = {1, 2, 3};
then what is the type of &array? Is it int**, or some
other type?
It should be int* instead of int **, because an array name
is _not_ a pointer.<snip>
Hmm, I made a mistake. Well, array name is an odd thing, it
can be a type of an array type, like here, when you apply
address operator to it; it can also be a pointer of the same
type as the elements within that array, e.g. when it is passed
as argument to a function.
WANG said:hpsoar wrote:int array[] = {1, 2, 3};
then what is the type of &array? Is it int**, or some other type?It should be int* instead of int **, because an array name is _not_
a pointer.
You might want to test that hypothesis:
#include <iostream>
void func ( ) {
std::cout << "void\n";
}
void func ( int** ) {
std::cout << "int**\n";
}
void func ( int* ) {
std::cout << "int**\n";
}
void func ( int(*)[3] ) {
std::cout << "int(*)[3]\n";
}
int main ( void ) {
int array [] = {1,2,3};
func( &array );
}
Best
Kai-Uwe Bux
James said:Kai-Uwe Bux said:WANG Cong wrote:
hpsoar wrote:
int array[] = {1, 2, 3};
then what is the type of &array? Is it int**, or some
other type?
It should be int* instead of int **, because an array name
is _not_ a pointer.
You might want to test that hypothesis:<snip>
Hmm, I made a mistake. Well, array name is an odd thing, it
can be a type of an array type, like here, when you apply
address operator to it; it can also be a pointer of the same
type as the elements within that array, e.g. when it is passed
as argument to a function.
An array name is the name of an array. Always. When used in an
expression, it has the type of the array. Always.
You're getting confused by the fact that there is an implicit
conversion of array to pointer in a lot of contexts. Most, in
fact: sizeof, typeof, unary &, and binding to a reference are
the most obvious exceptions (obvious, in the sense that they
occur immediately to me); there could be others.
Just for fun, you might want to try:
<snip>
Such is the consistency of C++. (The problem, of course, is C
compatibility. Arrays in C are broken, and C++ can't fix them
without loosing compatibility completely.)
WANG Cong said:James Kanze wrote:An array name is the name of an array. Always. When used in an
expression, it has the type of the array. Always.
Hmmm, how about the expression array? It will be, at least in C,
translated into *(array+i), of course, it doesn't have an array type
here.
WANG Cong said:Mo, that is an expression, neither a variable nor an object.
James said:An array name is the name of an array. Always. When usedKai-Uwe Bux wrote:
WANG Cong wrote:
hpsoar wrote:
int array[] = {1, 2, 3};
then what is the type of &array? Is it int**, or some
other type?
It should be int* instead of int **, because an array
name is _not_ a pointer.
You might want to test that hypothesis:
Hmm, I made a mistake. Well, array name is an odd thing, it
can be a type of an array type, like here, when you apply
address operator to it; it can also be a pointer of the
same type as the elements within that array, e.g. when it
is passed as argument to a function.
in an expression, it has the type of the array. Always.
Hmmm, how about the expression array? It will be, at least
in C, translated into *(array+i), of course, it doesn't have
an array type here.
No, sizeof(array) is the size of an array, it is the array
type, of course, except when you apply sizeof inside a
function to an array passed as an argument.
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.