Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Lets put it another way

Reply
Thread Tools

Lets put it another way

 
 
Paul
Guest
Posts: n/a
 
      05-25-2011

"Joshua Maurice" <> wrote in message
news:70ecc085-405f-41c0-b191-...
On May 24, 3:56 pm, "Paul" <pchris...@yahoo.co.uk> wrote:
> "Joshua Maurice" <joshuamaur...@gmail.com> wrote in message
>
> news:b6334244-434f-4c62-954b-...
> On May 24, 6:54 am, "Paul" <pchris...@yahoo.co.uk> wrote:
>
> > *p2 does not attempt to access the deallocated memory.

>
> --Doesn't matter. It's UB. Attempting to read the pointer, not the
> --deallocated memory, is UB. At least it is according to the C spec, and
> --I expect that the C++ standard will follow suit if it hasn't already
>
> This pointer obviously points to something that has a value that is
> displayed on the screen as a memory address. It certainly doesn't point to
> the integer objects that were allocated by new, so what does it point to?
> How can you say it is UB if you do not first establish what it is pointing
> to?


--Take the following program:
-- #include <stdlib.h>
-- #include <stdio.h>
-- int main()
-- { char* a = (char*)malloc(1);
-- char* b = a;
-- free(a);
-- printf("%p\n", b);
-- }
--This program has UB in C, and as I said will likely have UB in C++, or
--it already is UB in C++. See the defect report for more details:

--http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_260.htm

This is not the same as what I did.

> --And I still don't know what you mean by array type object vs array
> --object. Until you explain that technical distinction to me, you're
> --literally just spouting effective nonsense, as you just invented those
> --terms and no one else knows what you're saying.
>
> Well consider the following:
>
> int arr[3]={0};
> std::cout<< arr;
>
> The above does not output an array object, it outputs a memory address.
> To output the array object you need to loop and dereference:
>
> for (int i=0; i<3; ++i){
> std::cout<< arr[i] << std::endl;
>
> }
>
> The array type object is a region of memory that contains a value that is
> some memory address.
> The array object is a region of memory than contains three integer
> objects,
> each with the value 0.


--I suggest you take a course in compilers, or read a book, like one of
--the Dragon Books, Red or Green. You have gross misunderstandings of
--both the C++ object model, and how compilers actually generate code.
--There is no such thing as an "array-type object", as you've defined
--it. In these examples, there are only array objects and pointer
--objects - including pointers to arrays and pointers to individual
--elements, not "array-type objects".

If there is no such thing as an array type object then what is the object
that is implicitly converted to a pointer, and stores a memory address?


--Consider:
-- void foo()
-- { int x[3];
-- int* y = x;
-- cout << y;
-- }

--"x" is a piece of text. It is a preprocessor token. It is an
--identifier for an auto (stack) variable. It names an object. It names
--an (array) object of type "int [3]". That array object has three sub-
--objects of type "int".


std::cout<< x;
//outputs a memory address.
std::cout<< typeid(x).name();
//outputs that x is an array type object.

"x" is an object that stores a memory address.
"x" is an array type object.

When the array to pointer conversion takes place what is converted to a
pointer?
It is not one of the three integer objects that is converted to a pointer,
it is the array type object.


--"y" is a piece of text. It is a preprocessor token. It is an
--identifier for an auto (stack) variable. It names an object. It names
--a (pointer) object of type "int*". It holds the address of the first
--element of the auto (stack) array x.

y is a pointer.

This function "uses" the following objects:
- the array object x, and its 3 unnamed int sub-objects,
- the pointer object y,
- the object cout.
-There is no "array-type object".

Thats your opinion but you do not acknoweldge the object that stores the
address of the array, the object that is converted to a pointer on assignemt
to y.


<snip>


 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      05-25-2011

"Ian Collins" <ian-> wrote in message
news:...
> On 05/25/11 08:11 AM, Paul wrote:
>> "Ian Collins"<ian-> wrote:
>>> On 05/25/11 12:58 AM, Paul wrote:
>>>>>
>>>> You are not addressing the what stores the memory address.
>>>
>>> Because there isn't an address to store. The typeid operator (like
>>> sizeof) works with types, not values. In a simple case such as this the
>>> operand is not evaluated. Until you understand this you will be stuck
>>> in
>>> limbo.
>>>
>>> I could have simplified my simplification further by writing
>>>
>>> std::cout<< typeid(int[3]).name()<< std::endl;
>>>
>>> See? No memory address just a type.
>>>

>>
>> There is an address stored.
>>
>> Look at the code :
>>
>> int main(){
>> int (*pp)[3] = (int (*)[3])new int[3];
>> std::cout<<*pp;
>> }
>> If this does not output an address what the hell is it?

>
> The value returned by new.


Which is an address value.

>
>>>> A memory address value is stored so there must be an object to store
>>>> this
>>>> value, you say there is no object so what is it that stores this value?
>>>
>>> There isn't an address. Where's the address in typeid(int).name()? Or
>>> sizeof(int)?
>>>

>> The address is shown in my code above.

>
> The address in your code id the value return by new. No amount of casting
> will change that.


The value returned from new is a pointer value that is an address.

Why do you think it is not an address?




 
Reply With Quote
 
 
 
 
Joshua Maurice
Guest
Posts: n/a
 
      05-25-2011
On May 25, 2:59*am, "Paul" <pchris...@yahoo.co.uk> wrote:
> "Joshua Maurice" <joshuamaur...@gmail.com> wrote in message
> --Take the following program:
> -- *#include <stdlib.h>
> -- *#include <stdio.h>
> -- *int main()
> -- { char* a = (char*)malloc(1);
> -- * *char* b = a;
> -- * *free(a);
> -- * *printf("%p\n", b);
> -- *}
> --This program has UB in C, and as I said will likely have UB in C++, or
> --it already is UB in C++. See the defect report for more details:
>
> --http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_260.htm
>
> This is not the same as what I did.
>


Yes it is.

> > --And I still don't know what you mean by array type object vs array
> > --object. Until you explain that technical distinction to me, you're
> > --literally just spouting effective nonsense, as you just invented those
> > --terms and no one else knows what you're saying.

>
> > Well consider the following:

>
> > int arr[3]={0};
> > std::cout<< arr;

>
> > The above does not output an array object, it outputs a memory address.
> > To output the array object you need to loop and dereference:

>
> > for (int i=0; i<3; ++i){
> > std::cout<< arr[i] << std::endl;

>
> > }

>
> > The array type object is a region of memory that contains a value that is
> > some memory address.
> > The array object is a region of memory than contains three integer
> > objects,
> > each with the value 0.

>
> --I suggest you take a course in compilers, or read a book, like one of
> --the Dragon Books, Red or Green. You have gross misunderstandings of
> --both the C++ object model, and how compilers actually generate code.
> --There is no such thing as an "array-type object", as you've defined
> --it. In these examples, there are only array objects and pointer
> --objects - including pointers to arrays and pointers to individual
> --elements, not "array-type objects".
>
> If there is no such thing as an array type object then what is the object
> that is implicitly converted to a pointer, and stores a memory address?
>
> --Consider:
> -- *void foo()
> -- *{ int x[3];
> -- * *int* y = x;
> -- * *cout << y;
> -- *}
>
> --"x" is a piece of text. It is a preprocessor token. It is an
> --identifier for an auto (stack) variable. It names an object. It names
> --an (array) object of type "int [3]". That array object has three sub-
> --objects of type "int".
>
> std::cout<< x;
> //outputs a memory address.
> std::cout<< typeid(x).name();
> //outputs that x is an array type object.
>
> "x" is an object that stores a memory address.
> "x" is an array type object.
>
> When the array to pointer conversion takes place what is converted to a
> pointer?
> It is not one of the three integer objects that is converted to a pointer,
> it is the array type object.
>
> --"y" is a piece of text. It is a preprocessor token. It is an
> --identifier for an auto (stack) variable. It names an object. It names
> --a (pointer) object of type "int*". It holds the address of the first
> --element of the auto (stack) array x.
>
> y is a pointer.
>
> This function "uses" the following objects:
> - the array object x, and its 3 unnamed int sub-objects,
> - the pointer object y,
> - the object cout.
> -There is no "array-type object".
>
> Thats your opinion but you do not acknoweldge the object that stores the
> address of the array, the object that is converted to a pointer on assignemt
> to y.
>
> <snip>


That's nice. You're welcome to join the adult discussion when you
decide to adopt the community's terms instead of inventing your own.
Good day troll or obstinate person.
 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      05-25-2011

"Joshua Maurice" <> wrote in message
news:70ecc085-405f-41c0-b191-...
On May 24, 3:56 pm, "Paul" <pchris...@yahoo.co.uk> wrote:
> "Joshua Maurice" <joshuamaur...@gmail.com> wrote in message
>
> news:b6334244-434f-4c62-954b-...
> On May 24, 6:54 am, "Paul" <pchris...@yahoo.co.uk> wrote:
>
> > *p2 does not attempt to access the deallocated memory.

>
> --Doesn't matter. It's UB. Attempting to read the pointer, not the
> --deallocated memory, is UB. At least it is according to the C spec, and
> --I expect that the C++ standard will follow suit if it hasn't already
>
> This pointer obviously points to something that has a value that is
> displayed on the screen as a memory address. It certainly doesn't point to
> the integer objects that were allocated by new, so what does it point to?
> How can you say it is UB if you do not first establish what it is pointing
> to?


Take the following program:
#include <stdlib.h>
#include <stdio.h>
int main()
{ char* a = (char*)malloc(1);
char* b = a;
free(a);
printf("%p\n", b);
}
This program has UB in C, and as I said will likely have UB in C++, or
it already is UB in C++. See the defect report for more details:

http://www.open-std.org/jtc1/sc22/wg...ocs/dr_260.htm

> --And I still don't know what you mean by array type object vs array
> --object. Until you explain that technical distinction to me, you're
> --literally just spouting effective nonsense, as you just invented those
> --terms and no one else knows what you're saying.
>
> Well consider the following:
>
> int arr[3]={0};
> std::cout<< arr;
>
> The above does not output an array object, it outputs a memory address.
> To output the array object you need to loop and dereference:
>
> for (int i=0; i<3; ++i){
> std::cout<< arr[i] << std::endl;
>
> }
>
> The array type object is a region of memory that contains a value that is
> some memory address.
> The array object is a region of memory than contains three integer
> objects,
> each with the value 0.


--I suggest you take a course in compilers, or read a book, like one of
--the Dragon Books, Red or Green. You have gross misunderstandings of
--both the C++ object model, and how compilers actually generate code.
--There is no such thing as an "array-type object", as you've defined
--it. In these examples, there are only array objects and pointer
--objects - including pointers to arrays and pointers to individual
--elements, not "array-type objects".

--Consider:
-- void foo()
-- { int x[3];
-- int* y = x;
-- cout << y;
-- }

--"x" is a piece of text. It is a preprocessor token. It is an
--identifier for an auto (stack) variable. It names an object. It names
--an (array) object of type "int [3]". That array object has three sub-
--objects of type "int".

The standard states that the identifier x is an array type. But you have
said it names an object which has an array type:
"..the type of the identifier in the declaration T D1 is
"derived-declarator-type-list T", then the type of the identifier of D is an
array type"


Also the C++ standard states the following:
"5 [ Note: conversions affecting expressions of array type are described in
4.2. Objects of array types cannot be modified, see 3.10. -end note ]"


So what is this object of array type that cannot be modified?
Both quotes taken form section 8.3.4 Arrays, and easy to find.

 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      05-25-2011

"Joshua Maurice" <> wrote in message
news:bce3ed3c-065a-430c-b182-...
On May 25, 2:59 am, "Paul" <pchris...@yahoo.co.uk> wrote:
<snip>
>
> --I suggest you take a course in compilers, or read a book, like one of
> --the Dragon Books, Red or Green. You have gross misunderstandings of
> --both the C++ object model, and how compilers actually generate code.
> --There is no such thing as an "array-type object", as you've defined
> --it. In these examples, there are only array objects and pointer
> --objects - including pointers to arrays and pointers to individual
> --elements, not "array-type objects".
>
> If there is no such thing as an array type object then what is the object
> that is implicitly converted to a pointer, and stores a memory address?
>
> --Consider:
> -- void foo()
> -- { int x[3];
> -- int* y = x;
> -- cout << y;
> -- }
>
> --"x" is a piece of text. It is a preprocessor token. It is an
> --identifier for an auto (stack) variable. It names an object. It names
> --an (array) object of type "int [3]". That array object has three sub-
> --objects of type "int".
>
> std::cout<< x;
> //outputs a memory address.
> std::cout<< typeid(x).name();
> //outputs that x is an array type object.
>
> "x" is an object that stores a memory address.
> "x" is an array type object.
>
> When the array to pointer conversion takes place what is converted to a
> pointer?
> It is not one of the three integer objects that is converted to a pointer,
> it is the array type object.
>
> --"y" is a piece of text. It is a preprocessor token. It is an
> --identifier for an auto (stack) variable. It names an object. It names
> --a (pointer) object of type "int*". It holds the address of the first
> --element of the auto (stack) array x.
>
> y is a pointer.
>
> This function "uses" the following objects:
> - the array object x, and its 3 unnamed int sub-objects,
> - the pointer object y,
> - the object cout.
> -There is no "array-type object".
>
> Thats your opinion but you do not acknoweldge the object that stores the
> address of the array, the object that is converted to a pointer on
> assignemt
> to y.
>
> <snip>


--That's nice. You're welcome to join the adult discussion when you
--decide to adopt the community's terms instead of inventing your own.
--Good day troll or obstinate person.


Is this your way of running away from the argument?

 
Reply With Quote
 
Joel C. Salomon
Guest
Posts: n/a
 
      05-25-2011
On May 25, 5:59*am, "Paul" <pchris...@yahoo.co.uk> wrote:
> If there is no such thing as an array type object then what is the object
> that is implicitly converted to a pointer, and stores a memory address?


That's the *name* of the array that implicitly converts to a pointer.
The name is a compile-time concept, though, and does not quite
correspond to what the Standard calls an "object".

("...The name of the song is called 'Haddocks' Eyes'!")

--Joel
 
Reply With Quote
 
Joshua Maurice
Guest
Posts: n/a
 
      05-25-2011
On May 25, 12:32*pm, "Joel C. Salomon" <joelcsalo...@gmail.com> wrote:
> On May 25, 5:59*am, "Paul" <pchris...@yahoo.co.uk> wrote:
>
> > If there is no such thing as an array type object then what is the object
> > that is implicitly converted to a pointer, and stores a memory address?

>
> That's the *name* of the array that implicitly converts to a pointer.
> The name is a compile-time concept, though, and does not quite
> correspond to what the Standard calls an "object".


No. There is an array object, and it is implicitly converted to a
pointer to the first element. Consider:

int x[3];
int (*y)[3] = x;
int* z = *y;

y is not the identifier of the array object. y is a pointer which
points to the array object. Derefencing y gives an expression of array
type, specifically "int[3]". Then a standard conversion sequence is
applied using the array-to-pointer conversion in the assignment to z.
 
Reply With Quote
 
Joshua Maurice
Guest
Posts: n/a
 
      05-25-2011
On May 25, 4:45*am, "Paul" <pchris...@yahoo.co.uk> wrote:
> "Joshua Maurice" <joshuamaur...@gmail.com> wrote in message
> --Consider:
> -- *void foo()
> -- *{ int x[3];
> -- * *int* y = x;
> -- * *cout << y;
> -- *}
>
> --"x" is a piece of text. It is a preprocessor token. It is an
> --identifier for an auto (stack) variable. It names an object. It names
> --an (array) object of type "int [3]". That array object has three sub-
> --objects of type "int".
>
> The standard states that the identifier x is an array type. But you have
> said it names an object which has an array type:
> "..the type of the identifier in the declaration T D1 is
> "derived-declarator-type-list T", then the type of the identifier of D isan
> array type"


Semantic quibble. The same meaning applies. The standard and most
people often conflate identifiers and what they identify. Usually
there is no ambiguity of meaning. There is no ambiguity of meaning
here either.

> Also the C++ standard states the following:
> "5 [ Note: conversions affecting expressions of array type are described in
> 4.2. Objects of array types cannot be modified, see 3.10. -end note ]"
>
> So what is this object of array type that cannot be modified?
> Both quotes taken form section 8.3.4 Arrays, and easy to find.


Array objects cannot be (directly) modified, but their sub-objects can
be modified.

int main()
{
int x[3] = {};
int y[3] = {};
x = y; //ill-formed
x[0] = y[0]; //valid
}
 
Reply With Quote
 
Joshua Maurice
Guest
Posts: n/a
 
      05-25-2011
On May 25, 1:42*pm, Joshua Maurice <joshuamaur...@gmail.com> wrote:
> On May 25, 12:32*pm, "Joel C. Salomon" <joelcsalo...@gmail.com> wrote:
>
> > On May 25, 5:59*am, "Paul" <pchris...@yahoo.co.uk> wrote:

>
> > > If there is no such thing as an array type object then what is the object
> > > that is implicitly converted to a pointer, and stores a memory address?

>
> > That's the *name* of the array that implicitly converts to a pointer.
> > The name is a compile-time concept, though, and does not quite
> > correspond to what the Standard calls an "object".

>
> No. There is an array object, and it is implicitly converted to a
> pointer to the first element. Consider:
>
> * int x[3];
> * int (*y)[3] = x;
> * int* z = *y;
>
> y is not the identifier of the array object. y is a pointer which
> points to the array object. Derefencing y gives an expression of array
> type, specifically "int[3]". Then a standard conversion sequence is
> applied using the array-to-pointer conversion in the assignment to z.


Meh. Crap. That's what I get for posting code samples without running
it through a compiler. Here:
int x[3];
int (*y)[3] = &x;
int* z = *y;
 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      05-25-2011

"Joshua Maurice" <> wrote in message
news:c040a44a-9a0d-4435-9c90-...
On May 25, 12:32 pm, "Joel C. Salomon" <joelcsalo...@gmail.com> wrote:
> On May 25, 5:59 am, "Paul" <pchris...@yahoo.co.uk> wrote:
>
> > If there is no such thing as an array type object then what is the
> > object
> > that is implicitly converted to a pointer, and stores a memory address?

>
> That's the *name* of the array that implicitly converts to a pointer.
> The name is a compile-time concept, though, and does not quite
> correspond to what the Standard calls an "object".


--No. There is an array object, and it is implicitly converted to a
--pointer to the first element. Consider:

-- int x[3];
-- int (*y)[3] = x;
-- int* z = *y;

I think you missed an &, line 2 should be:
int (*y)[3] = &x;



--y is not the identifier of the array object. y is a pointer which
--points to the array object. Derefencing y gives an expression of array
--type, specifically "int[3]". Then a standard conversion sequence is
--applied using the array-to-pointer conversion in the assignment to z.


Anyway so this array object is described in the standard as a non modifiable
object of array type. SO with :
int arr[5];

arr is an object of array type. Do you agree with this?
and when we do this:
int (*pparr)[5] =&arr;

pparr is a pointer to an object of array type. Do you agree with this?


The array type object , is an object that could be described as a non
modifiable pointer to the array of ints, with added typeinfo to support C++
references, sizeof and typeid.
Do you agree with this? If not what do you think is wrong about it?




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why does the following with Queue, q.put('\x02', True) not put itin the queue? Gabriel Rossetti Python 3 04-25-2008 03:41 PM
OT: Lets all get high James MCSE 93 10-19-2005 05:45 PM
Review: Lets get a T@2 Part 1 Silverstrand Reviews & How-To's 0 06-20-2005 02:34 AM
Another way to put labels on page than asp:label tshad ASP .Net 2 04-08-2005 12:00 AM
is there a hardware / driver combination out there the lets win2k connect to the network before login?? christiane kewitz Wireless Networking 1 02-13-2005 01:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57