On Thursday, 3 October 2019 at 14:13:55 UTC, IGotD- wrote:
According to the GC documentation this code snippet
char* p = new char[10];
char* q = p + 6; // ok
q = p + 11; // error: undefined behavior
q = p - 1; // error: undefined behavior
suggests that char *p is really a "fat pointer" with size
information.
No it's not. char* is a plain pointer.
The example is wrong, since you can't assign a new char[10] to
char*.
Probably they mean something like:
auto arr = new char[10]
char* p = arr.ptr;
...
This code actually compiles, but its behaviour is undefined, so
it is a logical error.
In D arrays are fat pointer instead:
int[10] my_array;
my_array is actually a pair ptr+length.