Hi everyone,
I stumbled upon a CppCon talk
https://youtu.be/_qzMpk-22cc?t=1277
From 21:15 to 25:00, the speaker claims that the following code is fine in C but undefined behavior in C++:
struct X
{
int a;
int b;
};
X* get_X()
{
X* p = (X*)malloc(sizeof(struct X));
p->a = 1;
p->b = 2;
return p;
}
He talked about some rules in C++ Standard that claim that this is UB.
Shouldn't the C be the subset of C++?
And what is the speaker talking about?
I am asking this because there is similar code in handmade hero codebase.
Thanks.