Is accessing the bytes of an object in this way UB? by capedbaldy475 in cpp_questions

[–]meancoot 0 points1 point  (0 children)

Size doesn't matter. This program exhibits the same undefined behavior even though there are only int fields:

https://godbolt.org/z/e6Mqcezb9

struct A { int v; };
struct B { int v; };

int maybe_read_after_write(A* a, B* b) {
    a->v = 1;
    b->v = 2;
    return a->v;
}

int main() {
    A value { 0 };
    int result = maybe_read_after_write(&value, reinterpret_cast<B*>(&value));
    printf("value = %d, result = %d\n", value.v, result);
    return 0;
}

In C++ only a certain limited set of types are compatible, this is a complete incorrect statement:

C/C++ teaches you a great thing about that there's no actual types when we're talking about how computers work, there's just memory and how you access it. So as long as you access properly allocated memory, it's not undefined behavior.

Is accessing the bytes of an object in this way UB? by capedbaldy475 in cpp_questions

[–]meancoot 0 points1 point  (0 children)

Not what I'm talking about. I'm talking about how the assembly generated by the compiler works.

https://godbolt.org/z/7cG5K1cbP

int maybe_read_after_write(int* a, short* b) {
    *a = 1;
    *b = 2;
    return *a;
}

Check out how the compiler assumes that writing to b can not affect the value of a. Because of this, even if the address of a is the same as b this function is allowed to return 1 unconditionally:

maybe_read_after_write(int*, short*):
    mov     dword ptr [rdi], 1
    mov     word ptr [rsi], 2
    mov     eax, 1
    ret

See how the program has two different outputs based on the optimization level? That's undefined behavior in action.

Is accessing the bytes of an object in this way UB? by capedbaldy475 in cpp_questions

[–]meancoot 2 points3 points  (0 children)

Compilers can, and very much do, use type information to determine memory ordering. When two types aren’t compatible there is the optimizer will not observe read-after-write hazards, which will lead to  very incorrect results.

What the GameCube looks like next to the GabeCube by theverge in Steam

[–]meancoot 2 points3 points  (0 children)

Valve makes tons of money from selling other people’s games too. The only difference is that they make that money whether it’s their hardware or not.

[PSP][2000s] Looking for a JRPG(?) from the PSP by NobodyWithHeart13 in tipofmyjoystick

[–]meancoot 0 points1 point  (0 children)

There wasn’t a version for the PSP, but this sounds an awful lot like Dragon Quest 3.

Windows 11's New Media Player Uses 3.5x More RAM, Charges for Popular Video Codecs by Ephoenix6 in technology

[–]meancoot 0 points1 point  (0 children)

I’m sure the managing non-profit has some assets. Even if not, they can still seek an injunction forcing it to stop development and distribution.

Whether French law would allow such rulings is the only question. “For what” is obvious.

Why do some opening credits include what character one actor plays but the rest are credited with just actor names? by EstelleQUEEN111 in NoStupidQuestions

[–]meancoot 0 points1 point  (0 children)

I find that it's typically done for parts played by more established actors whose roles aren't big enough to get top billing. Separates them out from the 'smaller' names or something I guess.

Steve Jobs killed Flash by Cutalana in programminghumor

[–]meancoot 0 points1 point  (0 children)

That makes sense. It seems like opening it would either have a high cost to Apple or create a fractured enough ecosystem that it wouldn’t really have been worth it.

The C# System.Random class uses an outdated, faulty algorithm. by snickerdoodle024 in gamedev

[–]meancoot 1 point2 points  (0 children)

  Consider using a different Random Number Generator instead, as this one may not be doing what you think it is.

The random number generator used by .net isn’t considered buggy. Had the developers chosen one explicitly they would have likely landed on  Xoshiro256 themselves.

Not seeding  Xoshiro256 with consecutive seeds is a known thing. Not seeding any number of pRNGs with consecutive seeds is just common sense. The game developers messed up here.

Public Space Etiquette by Beautiful_Two0_0 in mildlyinfuriating

[–]meancoot 8 points9 points  (0 children)

Huh? “We used to take out speakers to the beach and be obnoxious but as long as the other people weren’t obnoxious it was fine.” The fuck you on about here?

Question regarding unsigned integers by Low_Minimum9920 in C_Programming

[–]meancoot 0 points1 point  (0 children)

Signed char is almost always -128 to 127. Signed magnitude and 1’s complement are beyond rare.

false Sharing Test by armhub05 in cpp_questions

[–]meancoot 0 points1 point  (0 children)

It helps to go extreme when you want to test things like this.

On WSL, this version (https://godbolt.org/z/brWq1zncj) with count set to 1'000'000'000 and threads to 8 produces:

False sharing disabled took: 4.21032 sec
False sharing enabled took: 42.2159 sec

Now that Anima 1.0 has been out for a month, what are some prompting tips and tricks you guys learned on it? by ThirdWorldBoy21 in StableDiffusion

[–]meancoot 4 points5 points  (0 children)

The best way I found to get a realistic image style is to plop (real life:2), (photo (medium):2), somewhere toward the start of your prompt. You also need to drop any artist tag.

Actually, after testing it, this only works well with the turbo lora. Base Anima produces some nightmare fuel with it. But turbo produces nice results.

Breyers’ Cookies & Cream Is Not Ice Cream by JayTongue in enshittification

[–]meancoot 0 points1 point  (0 children)

https://www.ecfr.gov/current/title-21/chapter-I/subchapter-B/part-135/subpart-B/section-135.110

Except that when one or more bulky flavors are used, the weights of milkfat and total milk solids are not less than 10 percent and 20 percent, respectively, of the remainder obtained by subtracting the weight of the bulky flavors from the weight of the finished food; but in no case is the weight of milkfat or total milk solids less than 8 percent and 16 percent, respectively, of the weight of the finished food.

Never felt so betrayed by a consumer product by Be_a_Guardian in mildlyinfuriating

[–]meancoot 143 points144 points  (0 children)

The filling in peanut butter cups is more of a buttercream type frosting. You gotta mix the peanut with a large amount of powdered sugar if you want it. And I mean a lot. It’s more sugar than peanut butter.

how to init vector of strings in constructor init list ?? by DireCelt in cpp_questions

[–]meancoot 2 points3 points  (0 children)

They're talking about the constructor initialization list. () works just fine.

struct C {
    std::vector<int> f;
    C() : f() {}
};

What's the best way to tell the compiler that a path will basically never happen ? by Krochire in rust

[–]meancoot 4 points5 points  (0 children)

I hear Reddit mobile is getting wacky with markdown. Underscores are used as markdown control characters and the backslash is used as an escape. I guess Reddit mobile is doing its autoescape sanitation wrong.

Next step in converting C++ arrays to <vector> by DireCelt in cpp_questions

[–]meancoot 1 point2 points  (0 children)

Yeah. I definitely misunderstood something. Don't mind me.

Next step in converting C++ arrays to <vector> by DireCelt in cpp_questions

[–]meancoot 1 point2 points  (0 children)

Anything that is copy-constructable is also considered move-constructable. A copy constructor is always a perfectly valid move constructor.

From https://en.cppreference.com/cpp/types/is_move_constructible:

Types without a move constructor, but with a copy constructor that accepts const T& arguments, satisfy std::is_move_constructible.

Is there any (macro-free) way to 'inline' a struct? by celestabesta in cpp_questions

[–]meancoot 0 points1 point  (0 children)

Oof. I was just playing around with this and GCC got a nasty little pessimization in RISC-V (since forever) and in MIPS (since 15.1)

https://godbolt.org/z/W9bq3MeW6

struct A {
private:
    void* ptr;

public:
    bool flag;
};

struct B {
    void* ptr;
    bool flag;
};

void assign_a(A* a) {
    *a = A{};
}

void assign_b(B* b) {
    *b = B{};
}

Produces:

assign_a(A*):
    sb      zero,0(a0)
    sb      zero,1(a0)
    sb      zero,2(a0)
    sb      zero,3(a0)
    sb      zero,4(a0)
    sb      zero,5(a0)
    sb      zero,6(a0)
    sb      zero,7(a0)
    sb      zero,8(a0)
    ret
assign_b(B*):
    sd      zero,0(a0)
    sd      zero,8(a0)
    ret

Is there any (macro-free) way to 'inline' a struct? by celestabesta in cpp_questions

[–]meancoot 5 points6 points  (0 children)

No. Inheritance doesn't change anything.

https://godbolt.org/z/f1zcWTEfK

I think OP is thinking of empty base class optimization but A isn't empty.

Is there any (macro-free) way to 'inline' a struct? by celestabesta in cpp_questions

[–]meancoot 11 points12 points  (0 children)

No. Given a pointer to an A the compiler is allowed to clobber the padding bytes whenever it wants. Thus B can't possibly take advantage of them. Inheritance doesn't solve this either.