What is the point of const?

What is the point of const?

Attached: 1555096141115.jpg (700x400, 150K)

you can't accidentally change the value and the compiler can optimize it better

>compiler can optimize it better
How true is that on a scale from false to true

The point is to communicate to the person reading the code that the value isn't supposed to change.

It's useful for manipulating higher order functions.
x >> y = x >>= \_ -> y

It's false. In C++ you literally have a keyword to break the promise (mutable), and in C you can just cast it away.
The point of const is code readability and maintainability.

Completely false current year. Maybe true in 1980. Gcc and clang do whatever the fuck they want to your code.

This. Its an enforcement/communication feature. It warns you if you try and violate it.

>haskell fag
How is unemployment going?

Very well thankyou user

In embedded systems you can have const placed in ROM.

To let women contribute more to tech.

Attached: 1517871722105.png (1340x1226, 275K)

preventing bugs and saving you time. Also readability

It's true. While it doesn't necessarily mean it WILL optimize it better, it however means it CAN, POTENTIALLY optimize it better, since it's additional information for the compiler.

The point is exactly that you can't ACCIDENTALLY modify a value, it don't mean you can't intentionally do it if so you wish (although it's usually UB). C++ protects against accident, not against fraud.

That said, I completely agree with Carmack on this. Use const whenever possible in C++ and C.

>The point of const is code readability and maintainability.
Sounds homosexual

very true if you know what to look for.
think of code like
int i = 0;
....
printf("%d", i);
do_something(&i);
printf("%d", i);

here, if the argument is const int* the compiler is allowed to read i into a nonvolatile register, and not reread it after the call

b&r

This has actually inspired me to look into contributing to open source projects. I always figured you had to make substantial contributions, which seemed like a lot of work to do for free. I guess not lol.

true

helps keep you from breaking code and also communicates intent

You do realize that casting away const is explicitly UB right, you fucking dumbass.

The compiler is "allowed" to do that whether or not you use const, and will do so if it can determine that you don't modify i in do_something (which it can if you don't)

If your first-ever contribution is a bloated patch, you have zero chance of it getting in.

>look at me I'm retarded
you really don't know what you're talking about do you.

Attached: Screen Shot 2019-04-13 at 5.49.21 PM.png (1090x676, 145K)

determining that is far from easy if you consider a complex function, maybe cast into void* or whatever. the more type info you feed to optimizer-chan the better she can do.

Now put do_something(&i) in a different object file.

First of all, I hate you