"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.