The cream is only good because of the cookie (oreo)

I hear alot ppl saying its just the cream thats good but u could never eat more than a little cream raw it would just be bad and u will get tired of it. The combination of it with the cookie is what actually makes da thing good.

reddit.com
u/Ok_Being6831 — 1 month ago

Why is this ub?

edit: sry, i will add a bit more context edit2: thank yall for answering, sry but cant reply to everyone i think i understand it now

Suppose i have a simple struct with a int or two and no methods, nothing and i have i memory address that is properly aligned for it and enough space, why would this be ub?

struct Test {
    int x;
    int y;
};
void* mem = malloc(sizeof(Test));
Test* ptr = static_cast<Test*>(mem);
ptr->x = 1000;

So as ppl told me, smth like this wouldnt be ub, would that change if the object had methods and stuff, if so why

I tried to look it up but just got a whole bunch of 'lifetime issues', and I didint really get it since I am the whose managing this memory. I was told that using placement new would be 'safer'/'better'.

reddit.com
u/Ok_Being6831 — 2 months ago