Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with const?

Tags:

c++

c++11

What are the known shortfalls of const in C++ and C++0x?

like image 985
Puppy Avatar asked Jan 12 '11 14:01

Puppy


People also ask

What is the point of const?

The const keyword specifies that a variable's value is constant and tells the compiler to prevent the programmer from modifying it. In C, constant values default to external linkage, so they can appear only in source files.

What const mean?

Const (constant) in programming is a keyword that defines a variable or pointer as unchangeable. A const may be applied in an object declaration to indicate that the object, unlike a standard variable, does not change. Such fixed values for objects are often termed literals.

What is const {} in JS?

The const declaration creates a read-only reference to a value. It does not mean the value it holds is immutable—just that the variable identifier cannot be reassigned. For instance, in the case where the content is an object, this means the object's contents (e.g., its properties) can be altered.

Does C have const correctness?

In C, C++, and D, all data types, including those defined by the user, can be declared const , and const-correctness dictates that all variables or objects should be declared as such unless they need to be modified.

Can a car be const?

It is perfectly legal for a compiler to deduce const for auto if it is not changing program functionality in any way. That also includes checks if there are const and non-const member functions available.

What does constant mean C++?

Constants refer to fixed values that the program may not alter and they are called literals. Constants can be of any of the basic data types and can be divided into Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean Values.


1 Answers

The only thing wrong with const is that it is seriously underrated by to many developers. It's one of the best tools in C++'s toolbox, very sharp, and yet not dangerous to cut yourself with.

like image 113
sbi Avatar answered Oct 02 '22 13:10

sbi