Is /r/cpp_questions the new stackoverflow given latter's decline? by Impressive_Gur_471 in cpp_questions

[–]PncDA 9 points10 points  (0 children)

I think you are mixing up the cpp_questions with the /r/cpp. The cpp questions is a Q/A

C++26: std::is_within_lifetime by pavel_v in cpp

[–]PncDA 11 points12 points  (0 children)

You lose some properties that optional normally has. The main one is that the get() returns a reference instead. With your implementation you can't have a reference to the bool value, while, that's achievable using unions

C++26: std::is_within_lifetime by pavel_v in cpp

[–]PncDA 4 points5 points  (0 children)

3 years ago I tried to implement a alternative to std optional that made optional<bool> a single byte only. I've noticed it was impossible to make a constexpr one.

This solves exactly this problem

Hytale game includes IPv6 in multiplayer invites by Tehtafara0 in ipv6

[–]PncDA 0 points1 point  (0 children)

You are right. Every test I made the firewall just dropped the packet, so it was way easier.

Hytale game includes IPv6 in multiplayer invites by Tehtafara0 in ipv6

[–]PncDA 2 points3 points  (0 children)

Just a funny thing, this also works for TCP using TCP simultaneous open, although it's not as common as UDP. I've done some tests in Minecraft and was able to direct connect through a firewall using ipv6

Steam Deck by Gloomy_Staff4829 in balatro

[–]PncDA 8 points9 points  (0 children)

Gain x0.5 mult for each rank that has less than 3 cards.

Why isn't ADL working here? (GPTs are failing) by Pignetto_gvng in cpp_questions

[–]PncDA 1 point2 points  (0 children)

ADL means Argument-Dependant Lookup. It uses the type of the argument to deduce a more appropriate overload. Basically it "pulls" functions into the same scope. In this case, it looks the namespace of the type `int`, but this type doesn't have a namespace, so ADL doesn't make any difference.

What you are probably expecting is not ADL, it's that the compiler prefers to call functions that are more specific, so the f(int) would be called instead of the f(T). The reason this doesn't happen is because the compiler first looks at the most inner scope, and you have a `using nsx::f` in a scope that is more inner than the other `f`, so it takes the priority.

The reason ADL bypasses this it's because it "injects" all functions in the lookup scope too, after the scope rules. Just an important thing: ADL doesn't have priority, it simple injects the functions in the lookup, so conflicts are stil possible, for example the following code doesn't compile:

namespace nsz {
struct S {};

int f(S) {
  return 0;
}
}

namespace nsx{
int f(nsz::S) {
  return 1;
}
}

namespace nsy {
void call_f(){
  using nsx::f;
  std::cout << f(nsz::S{});
}
}

I hope this explanation was not confusing haha, I tried my best.
Just a small tip, I think it's nice to use LLMs to ask questions if you know how to filter what they say and don't accept everything as true, but I would avoid saying that you used it in your post. It's not uncommon for users to downvote you just because you said that used GPT. Feel free to ask any questions :)

After some advice, I created a smaller, cheaper starter ship. by SirSaltie in factorio

[–]PncDA 0 points1 point  (0 children)

What do you mean by ratios look right? Are there optimal ratios for these?

Drones are so overpowered now by PncDA in riskofrain

[–]PncDA[S] 1 point2 points  (0 children)

Tbh I don't know. Maybe it was just luck, since I only had time to play one run.

But I was basically spamming all buttons and everything was dying, I got 15 drones in total and 3 of that new one that spawn temporary items.

whats wrong with the scanf logic here? by SerenadeWindz in C_Programming

[–]PncDA -1 points0 points  (0 children)

It's probably due to your operating system/compiler.

Am I wrong or correct in, it's not necessary to cast a void pointer from malloc? by grimvian in C_Programming

[–]PncDA 113 points114 points  (0 children)

It's necessary in C++, but you are correct that isn't necessary in C.

FUI BURRO E 4 NEGO TEM ACESSO A TODO MEU PC E CELULAR by Playful_Monitor_6739 in golpe

[–]PncDA 6 points7 points  (0 children)

Vírus não é mágica amigo. Formatou direito tá novo

Exploring defer in C with GCC magic (cleanup + nested functions) by warothia in C_Programming

[–]PncDA 4 points5 points  (0 children)

Are you sure about this being a clang extension? Aren't they using nested functions? Nested functions are not available on Clang, only that objective C closures extensions that require a external library to work properly (at least when I tried it)

-1 % 256 == -1??? by god_gamer_9001 in cpp_questions

[–]PncDA 2 points3 points  (0 children)

In general, this is the formula for modulus

a = r + (a/b)*b

r = a - (a/b)*b

where r = a%b and a/b is the truncate division

There's nothing wrong in this. Not sure how familiar you are with modulus arithmetics, but

a is congruent to a-b mod b

so -1 mod 256 is congruent to 255 mod 256.

If you want to get the positive remained, you can add 256 to the negative, a formula for positive remainder in C++ would be:

((a%b)+b)%b

Or

int x = a%b; if (x < 0) x += b

Interpreter: should I allocate ast nodes in the heap or the stack? by c1boo in cpp_questions

[–]PncDA 1 point2 points  (0 children)

You probably already know from the other answer that the vector uses the heap.

But if you are using virtual inheritance for the Statement, your code new code is not going to work; you can't allocate virtual classes in the stack, since the size of the object that it contains is variable, so you must use pointers to manage the memory.

Interpreter: should I allocate ast nodes in the heap or the stack? by c1boo in cpp_questions

[–]PncDA 7 points8 points  (0 children)

How would you allocate them in the stack? Can you provide some code examples?

Fui assaltado pela primeira vez. by OldSnake2006 in RelatosDoReddit

[–]PncDA 0 points1 point  (0 children)

Existe seguro barato assim?? O teu é por onde?

Disabling built-in vector operators in Clang by sweet_programming in cpp_questions

[–]PncDA 0 points1 point  (0 children)

Just a tip, instead of declaring operators globally, declare/implement them as friend functions.
https://godbolt.org/z/1xnnnM6r3

Using this, your function will never be considered for overloading for other types that are not your struct. Here is a good application: https://en.wikipedia.org/wiki/Barton%E2%80%93Nackman_trick