Zel
int[1] ={10}
Alex
https://stackoverflow.com/questions/18222926/why-is-list-initialization-using-curly-braces-better-than-the-alternatives
Alex
so probably this is List initialization does not allow narrowing
V01D
int[1] ={10}
I am not talking about arrays
Alex
the key issue. however I did not see curly bracket initializer in production code for not array/struct
V01D
Hm, okay. Again wanna say this was shown in C++17, so might be special for C++17
Zel
Does the book explain it or refference an appendix entry?
V01D
https://www.learncpp.com/cpp-tutorial/variable-assignment-and-initialization/
Alex
Hm, okay. Again wanna say this was shown in C++17, so might be special for C++17
probably, cause c++17 allows you: auto var{ 5 } and it will be deduced as int no more as std::initializer_list<int>.
Alex
However, I am not going to write like this. int x = 10; is std and clear way
V01D
Okay, I will use standard way then
Merazi
https://www.learncpp.com/cpp-tutorial/variable-assignment-and-initialization/
Brace initialization has the added benefit of disallowing “narrowing” conversions. This means that if you try to use brace initialization to initialize a variable with a value it can not safely hold, the compiler will throw a warning or an error. That's what it says 🤔
Zel
Oh, like how float narrows down to int, ie chops of the decimals.
Merazi
Maybe it's just for debugging purposes? (Idk, I'm a newbie programmer)
Zel
meh I use narrowing for multiple reasons :P
LostInNeonCity
Hi , is it possible to install kali linux without ubuntu??
Alex
yes
Alex
you don`t need ubuntu at all
V01D
Kali is for professionals though. Even says on the site.
Merazi
Yeah, but that pfp is OP :P
Interesting, when using brace initialization you do get an error
V01D
Try -std=C++17
Merazi
Try -std=C++17
Without braces
LostInNeonCity
Thanks guys , i'm confused cuz i didn't know the first step to start learning about linux .
Merazi
Try -std=C++17
With braces
V01D
Spend a month or two minimum
V01D
Ubuntu is fine
Merazi
Thanks guys , i'm confused cuz i didn't know the first step to start learning about linux .
You can start with ubuntu, there's no reason to be ashamed by that Btw, kali is based in debian, ubuntu is based on debian as well so if you learn ubuntu (command line utilities included) you will be able to use kali
LostInNeonCity
Okey thank u so much guys , i will install it ☺️
V01D
You might break kali alot. Kali is different from normal debian systems. Kernel is more modified, many standard things are gone, minimal repo
Merazi
You might break kali alot. Kali is different from normal debian systems. Kernel is more modified, many standard things are gone, minimal repo
Well that's true, but if you're comfortable inside a terminal it wont be a big deal to fix
V01D
Yeah, IF. I know cd and ls blew my mind way back when, lmao
V01D
Linux is just great
V01D
A gift for programmers from the gods. make, perl, python, ruby, bash, gcc, g++, clang, and more are usual on debian. And NO INSTALLERS
Merazi
yeah, in a lot of scenarios is easier to setup than windows :P (You gotta read manuals tho)
V01D
V01D
Same applies to API and manuals
Merazi
Hahahahaha true
Zel
yeah function templates mean a lot less than function templates cuopled with -examples- :/
Daniele
this is so true
Daniele
andd wastes so much time
V01D
Anyone know why g++ is so slow? gcc can compile a hello world faster than g++ can - It takes g++ like 2 seconds! Can I speed up g++ anyway? Is there a better cross platform C++ compiler?
Daniele
guys
Daniele
what's the shortest sorting algorithm to write in C?
V01D
https://www.educba.com/sorting-in-c/
Bernardes
I am on learncpp.com rn, and I saw that curly brace initialization is better than brace initialization. But why? Why is int x{ 10 }; better than int x( 10 );
This is an initialization notation (c++11) that outlaws narrowing conversions. To help avoid unsafe conversions
Andrew
also insertion sort is short
V01D
Ahh, okay. Thank you
Bernardes
Ahh, okay. Thank you
👍🏾👍🏾👍🏾
V01D
👍🏾👍🏾👍🏾
So the code is safer, but is the claim that the code runs faster true?
V01D
And when should I use this type of variable declaration? When I have some sort of user interaction, perhaps?
Bernardes
Idk if it's faster, but you should use if you think that a conversion might lead to a bad value. Like convert  int to char or something like that
V01D
Thanks
Alex
check aliases, command line options etc
Bernardes
Thanks
Glad to help
V01D
g++ is part of the gcc. can`t understand you
g++ is just slower than gcc is for some reason..
Alex
because gcc use other compiler than g++(see file extension) or use another options
olli
Anyone know why g++ is so slow? gcc can compile a hello world faster than g++ can - It takes g++ like 2 seconds! Can I speed up g++ anyway? Is there a better cross platform C++ compiler?
need more details, for me its 426ms (g++) vs 438ms (gcc) for the following code #ifdef __cplusplus #include <cstdio> #else #include <stdio.h> #endif int main() { #ifdef __cplusplus std::puts("Hello World\n"); #else puts("Hello World\n"); #endif return 0; } Using <iostream> significantly increases the time needed since the whole header needs to be parsed, templates need to be instantiated and exceptions are also only part of C++. Can you share your code?
Alex
https://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc
olli
Simple hello world: #include <iostream> int main() { std::cout << "Hello" << std::endl; return 0; }
g++ -E generates > 20000 lines for this simple example, where as using printf generates ~500 hence it should be no surprise that this version is way slower to compile. https://godbolt.org/z/q5xKr9
olli
I am sure your explanation is correct. I compiled with g++ and gcc - both where slow. I took out iostream and it was faster. Thanks
gcc "becomes" g++ if your file has the C++ file extension gcc a.cpp => C++ g++ a.cpp => C++ gcc a.c => C g++ a.c => C++
V01D
I saw, via the -xc++ flag amongst others
V01D
I never knew g++ was so close to gcc. Thanks for the help.
Anonymous
/ok
da
Hi,everyone.If it returns from the main function, but there are other threads still executing, will the process terminate?
olli
Hi,everyone.If it returns from the main function, but there are other threads still executing, will the process terminate?
https://stackoverflow.com/questions/19744250/what-happens-to-a-detached-thread-when-main-exits
Anonymous
With braces
Braced initialization doesn't allow narrowing conversions