Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Grumm17972yNot sure what is the problem, but using
int i{0} is the same as int i = 0 in c++.
And using {} is actually a safer way too. Prefer {} initialization over alternatives unless you have a strong reason not to.
example :
int x2 = val; // if val == 7.9, x2 becomes 7 (bad)
int x3 {val}; // error: possible truncation (good) -
Yeah, you can also initialize variables with parentheses, which has on several occasions screwed me over when trying to declare methods
-
Grumm17972y@lbfalvy yeah, best practice is to pick one (for most '=') and stick to that one in the project.
But again, mostly of all devs will use '='.
Yet it is not the safest option to use in C++ (unless you learned C++ in the 80')
Here is some info on the convention :
https://github.com/isocpp/...
We are now at C++ 23... people should start to move on from the old ones.
(this was a new feature in C++ 11:
C++11 provides a syntax that allows for fully uniform type initialization that works on any object) -
@Grumm While I know the syntax, I have never seen it being used in a for loop, nor being mentioned as a better way to do things..
I think it's people just not knowing about it for the most part?
Thank you for the info~ -
@Grumm implicit truncating casts are just trouble all around, I'm not sure why c++ still hasn't put them behind a compatibility flag. I think some compilers at least produce a warning.
-
Grumm17972y@ElectroArchiver I agree that in a for loop it is not really needed. But if the code uses that for all the other variables, then yes it makes sense.
-
Grumm17972y@ElectroArchiver My bad. Don't worry, I think most don't use this syntax.
As long as it works, using '=' is fine and accepted.
Related Rants
-
xjose97x19Just saw a variable in C named like this: long time_ago; //in a galaxy far away I laughed no stop.
-
Unskipp24So this happened last night... Gf: my favorite bra is not fitting me anymore Me: get a new one ? Gf: but it ...
-
sam966911Hats off to this lady .... I would have just flipped the machine
I came to know and use C++ for 10 years now and I've just seen this syntax:
for(int i{0}; i<5; i++) { }
WTF is this shit??
rant
the devil
cpp
c++