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🔥
Thanks for checking! As expected :D
Well, GCC just could not optimize the code enough :)
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...
Danya🔥
Anyways, the microoptimizations without any reason are bad
Usually they are done by the people who does not know how to actually optimize code
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
\Device\NUL
gcc is so widely used that we can't just dismiss it...
Just because it's widely used it doesn't it's the best
Arnold
Anyways, the microoptimizations without any reason are bad
haha yeah, sometimes you encounter inline asm because it's 0.5% faster and all you can do is scream in horror
Danya🔥
Usually they are done by the people who does not know how to actually optimize code
And they try to optimize 2 jumps instead of O(n^3) algorithm
Danya🔥
haha yeah, sometimes you encounter inline asm because it's 0.5% faster and all you can do is scream in horror
I'm fortunate enough not to these "optimizations" unless they are absolutely needed
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
Ludovic 'Archivist'
like hot reload commands on something that may require emergency use of direct memory access
\Device\NUL
https://godbolt.org/z/87YfWsajY It is still the same
Atleast clang didn't use relative addressing anymore
Arnold
I find that C is only ever useful when I need to compile the software on a potato
It's strangely relaxing to write something more suited for a higher level language in plain C. Ever made a game in C?
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
VD
nowadays I mostly use dlang+grimoire for that
I did love dlang until they included a garbage collector (that it is optional doesn't matter)
Ludovic 'Archivist'
I did love dlang until they included a garbage collector (that it is optional doesn't matter)
Meh, there is worse things than a GC, I would have one anyway with the scripting language and having one here makes sense
Ludovic 'Archivist'
If dlang didn't have a GC, I would just use C++
Light
Depends on the coding guidelines of company
Company?? Bro, get out of matrix, you should open a company if they dont listen to your demands, i am already making millions by listening to my self (ludo coins)
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.
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
Ludovic 'Archivist'
Company?? Bro, get out of matrix, you should open a company if they dont listen to your demands, i am already making millions by listening to my self (ludo coins)
You sound like you are gonna recommend me both a financial placement with a 6% monthly interest rate and "zero risk™️" as well as a funding plan with an 400% interest rate that forces me to share 3% of my company with you
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
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
Can you explain me a little why std::move is doing this.. I am not moving the shared ptr.. but while creating it using make_shared, I move the pointee object to it
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
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; } }
In this case the result of i*2 will probably be stored in a register in both cases, so the variable will be optimized away anyway And if the code around will be very complex, then it can be that the second variant can be actually less efficient (I assume it can happen that while generating the code for the loop the compiler won't be able to make sure that a won't be used outside of the loop and will decide to store it on stack).
Pavel
But that just thoughts, I'm not sure if that can happen
borealis
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?
the initialization outside of the loop is redundant. if you're going to keep overwriting your previous object in every iteration, you can and probably should initialize it within the loop. if you have an object that is expensive to construct and destruct, it is better to initialize it once, outside of the loop, and keep reusing the same object
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.
不要惹胖虎
the world isn't easy that you want
Adaita (MedTech | Healthcare)
Company?? Bro, get out of matrix, you should open a company if they dont listen to your demands, i am already making millions by listening to my self (ludo coins)
Funny guy. Sounds like you are capable of replacing all the companies in the world. Coding guidelines are followed strictly in many companies for many advantages.
Light
I wanna send a codebut its little large how can i do that?
Light
(Sending code for evaluation)
кар карыч
кар карыч
No Files
txt too?
Danya🔥
txt too?
No files
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
Abdul
Okay
Danya🔥
Okay
What?
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
Diana
I want to compile my c code in vs code but it’s not going
Make sure you get the necessary plugins, or your compiler is up to date; try to configure your compiler into vs code.
Diana
Yes
Thanks. But I just wrote that to check my acceptance in the group.
\Device\NUL
Can someone tell how to use 128 bit integer in c++?
You can, but it's compiler extension