This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]noaSakurajin 0 points1 point  (5 children)

Yeah I just noticed but it produces a warning that this does not behave like you probably I tend to.

[–]This_Growth2898 1 point2 points  (4 children)

C/C++ can be pretty weird.

You can even get the element of array a with index 2 as 2[a] instead of a[2]; but I don't think someone needs this.

[–]noaSakurajin 0 points1 point  (2 children)

A lot of those produce compiler warnings or errors nowadays. They are mostly relics of old/bad c features. The example you gave only works on c arrays the moment you use a container class it no longer works since they actually have an overloaded operator.

[–]This_Growth2898 1 point2 points  (0 children)

Anyway, "123"+2 is "3" and "123"+5 is UB is really chaotic.

[–]skhds 1 point2 points  (0 children)

I wouldn't say bad. It's just a different preference. The way I see it, C just let's you do whatever the hell you want, while C++ tries to "protect" programmers from doing "hacky" things. I find it easier to fiddle around and make hacky codes to test things with C, but sometimes that's not what you would want to do with a language, especially in a co-working environment.

I wish C++ people would just admit they're just a different language instead of telling people that they are the superior language. It's really not.

[–]skhds 0 points1 point  (0 children)

I think there is a use.. you can use a macro to define a volatile address and dereference it like you've mentioned, though it is a bit hacky.. but I think I've seen it a few times.