const integers

M

Michael Wojcik

Mark McIntyre posted:


Not worth the paper it's printed on.

It's possible to invoke Undefined Behaviour in C++ -- one should accept that
before writing such an article.

You have entirely missed the point of the article, which is that
one particular expectation that some (particularly inexperienced)
programmers may have about C++ is unfounded; and that another
related expectation (regarding the mutability of constant strings)
was cultivated some time back but is now invalid in the environment
where it was once promoted.

These are important lessons. They may be ones you have already
learned, but that makes them no less important. This article conveys
them in a clear and succint manner; is it impossible that some reader
might thereby be informed?

The myth that all the world's a PC is pernicious, but not, perhaps,
as pernicious as the myth that all programmers are oneself.
 
E

ena8t8si

Mark said:
Mhm, indeed. Mind you thats a fairly unusual example, since strings
are the only data type with a subclass which is secretly constant. Its
harder to get that sort of error with doubles or ints.

That's because double/int literals are values and can't
be turned into objects (eg, by taking their address).
String literals are different because they are objects.
No one would complain if the type of 7 were const int
rather than int.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

I HAVE MADE AN IMPROVED INPUT FOR INTEGERS ONLY 3
Chatbot 0
to const or not to const 8
TF-IDF 2
casting const away 58
const or constant? 30
Command Line Arguments 0
Uhhhhh, What can I do next? 6

Members online

No members online now.

Forum statistics

Threads
474,188
Messages
2,571,002
Members
47,591
Latest member
WoodrowBut

Latest Threads

Top