Date: Sun, 26 Jan 2025 21:25:01 +0000
Eight months ago, I posted here saying that all pointer types should
be made intercompatible. Here's my original post:
https://lists.isocpp.org/std-proposals/2024/05/9773.php
With all the talk today on the topic of "Public inheritance with
banned conversion to base", I've just realised something. Consider the
following two classes:
struct Frog {
char c;
};
struct Monkey {
long long n;
};
Frog has an alignment of 1, whereas Monkey has an alignment of 8. So a
pointer to a Frog could possibly need more bits than a pointer to a
Monkey.
But now let's consider another translation unit in the same program:
struct Frog;
struct Monkey;
int main(void)
{
Frog *p = nullptr;
Monkey *p2 = nullptr;
}
This second translation unit doesn't know the alignment requirements
of either Frog or Monkey, but yet it can create a Frog* or a Monkey*.
This means that one of the following must be true:
(1) Any given class type will have its alignment requirements made
more restrictive so that any "basic pointer" can point to it.
(2) All pointers type are intercompatible and the same size.
be made intercompatible. Here's my original post:
https://lists.isocpp.org/std-proposals/2024/05/9773.php
With all the talk today on the topic of "Public inheritance with
banned conversion to base", I've just realised something. Consider the
following two classes:
struct Frog {
char c;
};
struct Monkey {
long long n;
};
Frog has an alignment of 1, whereas Monkey has an alignment of 8. So a
pointer to a Frog could possibly need more bits than a pointer to a
Monkey.
But now let's consider another translation unit in the same program:
struct Frog;
struct Monkey;
int main(void)
{
Frog *p = nullptr;
Monkey *p2 = nullptr;
}
This second translation unit doesn't know the alignment requirements
of either Frog or Monkey, but yet it can create a Frog* or a Monkey*.
This means that one of the following must be true:
(1) Any given class type will have its alignment requirements made
more restrictive so that any "basic pointer" can point to it.
(2) All pointers type are intercompatible and the same size.
Received on 2025-01-26 21:25:10