Arnold
Arnold
Switch wins again 💪🤘
Ludovic 'Archivist'
Clang leads to the optimal code in both case, but that is because the designers of clang know how to make AST that doesn't suck ass
Danya🔥
Look into clang :)
Danya🔥
Anyways, the microoptimizations without any reason are bad
Arnold
gcc is so widely used that we can't just dismiss it...
Ludovic 'Archivist'
Meh, I would be OK with switch in either hot code or code that relies on integer operations a lot
\Device\NUL
Look into clang :)
Clang in the godbolt didn't have -fno-pie enabled by default while GCC enable it
Arnold
Danya🔥
Danya🔥
Danya🔥
Even authors of LLVMs libc banned assembly in their code (unless the cases when you cannot just express something with C++)
Danya🔥
(yes, LLVM's libc is written in C++)
Danya🔥
Ludovic 'Archivist'
I find that C is only ever useful when I need to compile the software on a potato
aklil
Ludovic 'Archivist'
like hot reload commands on something that may require emergency use of direct memory access
Ludovic 'Archivist'
Ludovic 'Archivist'
nowadays I mostly use dlang+grimoire for that
Danya🔥
Ludovic 'Archivist'
At least someone uses dlang
If I could fire a missile everytime I see that Stepanov or Alecsandrescu wrote something dumb the world would have a lot more oceans
Ludovic 'Archivist'
phobos is a horrible mess
VD
Anyways, the microoptimizations without any reason are bad
I wouldn't call using a switch in place of if - else if - else a micro optimization. In quite a few cases a switch statement leads to more readable code than a long list of if-else branches. If a compiler can optimise it better (in many cases a switch statement can be optimised better) then all the more why I should use it. The point is that readability of code is more important and a switch statement helps there
Ludovic 'Archivist'
If dlang didn't have a GC, I would just use C++
borealis
thx andrew tate
Ілля
Hello everyone, if I store numeric integer variables of type char (-128...127) or unsigned char (0...255), does it make sense? I understand that this will save memory, since the char type takes only 1 byte, but it will also take time to convert from char to int. Does this method have any other pitfalls? Thx for answers.
Maxim
borealis
assuming x86, if it survives the compilation, you will need to read the value into a register to operate on it. in case of loading an int, it can be done with a mov. loading a char to a register will instead sign extend it with movsx. both of these take the same time to execute. in other words, using a char as an int incurs no more performance penalty than using an int as an int
The
Any idea in what case can a
std::vector<std::shared_ptr<const std:: string>>
have an empty shared ptr as a member..
I'm doing vec.erase(vec.begin())
vec.push_back
And at one place func(*vec.front())
As per my thinking vec.erase should always destroy the shared ptr completely correct.. even if doesn't, front and begin should move forward properly..
borealis
youre either pushing a nullptr into the vector or std::move'ing from a shared ptr. also removing from the front of a vector is very expensive, you might want to use std::deque instead
The
Chat Boss
Ілля Корнійчук sent a huge message, it has been re-uploaded as a file
Hello again, I have two cycles, in the first one I initialize a new variable at each iteration, ..
Ілля
Hello again, I have two cycles, in the first one I initialize a new variable at each iteration, and in the second one the variable is initialized outside the cycle, which option is more efficient?
int main() {
for (int i = 0; i < 5; i++)
{
int a = i*2;
cout << a;
}
{
int a=0;
for (int i = 0; i < 5; i++)
{
a = i*2;
cout << a;
}
}
Ludovic 'Archivist'
Ілля
Rather, the question here is in the logic itself, because instead of the int type, I can use another custom type that may take more time in the constructor. I'm just wondering if the compiler can somehow track and optimize this, or if the programmer has to foresee it?
Pavel
borealis
Pavel
But that just thoughts, I'm not sure if that can happen
borealis
actually, if construction is expensive but the assignment operator is cheap for your custom object, it would be better to construct once outside of the loop and keep assigning to it in every iteration. overall this is a context specific question and there's not a definitive answer without seeing the custom object
FriedRice
There is no difference, the compiler will just put a in a register.😂
FriedRice
But for coding style you probably want to declare a as closed as possible to where you will use a.
\Device\NUL
不要惹胖虎
the world isn't easy that you want
\Device\NUL
Light
I wanna send a codebut its little large how can i do that?
Light
(Sending code for evaluation)
Danya🔥
кар карыч
Danya🔥
кар карыч
Danya🔥
Light
I knew there must be some kind of sending no files rules, that is why i asked first.
Light
Ok i will prepare a github
Raw Hacker
Jisko vi C++ programming ka full course chahiye contact me
Raw Hacker
Zero to hero full C++ Tutorial means beginning to expert lavel courses
Danya🔥
Abdul
Okay
Danya🔥
Anonymous
Sorry mistake 😬
Pikachu
Can someone tell how to use 128 bit integer in c++?
Pikachu
some problems give overflow even on 64 bit integer
Diana
Can a C programmer transition to c++ programming with ease?
Ansu
I want to compile my c code in vs code but it’s not going
Vishnu
Diana
Yes
Thanks. But I just wrote that to check my acceptance in the group.
\Device\NUL