Post #75,215
1/17/03 4:38:07 PM
|
One of my directives for this port:
#define DO_NOT_FIX_OLD_CODE_FOR_THE_SAKE_OF_THE_PORT
etc. ;-)
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #75,225
1/17/03 5:22:29 PM
|
Re: One of my directives for this port:
I read Stroustrup's explanation of "const" in three different editions of his book, and still didn't really understand it.
-drl
|
Post #75,231
1/17/03 5:42:03 PM
|
The "const" attribute means that, within the given scope,...
the object may not be modified, i.e. for practical purposes is read-only (or constant).
Alex
"No man's life, liberty, or property are safe while the legislature is in session."\t-- Mark Twain
|
Post #75,246
1/17/03 7:31:13 PM
|
Because it's not supposed to be modified...
...i'd suspect that it's also not kosher to dereference a Const pointer. If a dereference is allowed then the program can backdoor a method to change the value by casting it to another type and then doing an assign.
Perhaps that's the point of the error message that Scott received?
|
Post #75,286
1/17/03 10:31:53 PM
|
Yes, I remember all that..
..but why bother? I know what I'm doing when I call a C function - it's pedantic and *against C spirit* to obess on such things.
In the end, you could take BS's approach and make FORTRAN+1 or ADD1TOCOBOL and it would end up violating those languages. He'd have some stupid obession about COMMON blocks in FORTRAN, maybe.
The funny thing is, the early parts of C++ really are improvements to (ANSI) C. It's the bizarre attempts to cover up a fundamentally procedural idiom that gets him into deep shit.
-drl
|
Post #75,300
1/17/03 10:58:51 PM
|
Re: why bother?
Because you don't "own" and may not know the innards of the function you use and the const is part of a compiler enforced interface spec that leads to more predictable code behavior.
When all the code is yours, it does not matter so much. Unless, like me, you may forget what you've done in a couple of weeks.
Alex
"No man's life, liberty, or property are safe while the legislature is in session."\t-- Mark Twain
|
Post #75,304
1/17/03 11:06:45 PM
|
Well, yes, that was what BS was obsessing on
..but why not just make an API with use instructions? If you use it wrong, you will get burned.
CAUTION: Don't use the space heater in a room filled with natural gas.
CAUTION: Remain clear of the blast zone.
CAUTION: Failure to deploy flaps in a timely manner will result in a stall and a fiery metallic death on landing.
CAUTION: Consuming ten times the recommended dosage of this medicine may produce symptoms such as breathlessness, little or no heartbeat, and lack of motivation.
You can't prevent people from being stupid. You have to give them the freedom to be smart.
-drl
|
Post #75,455
1/18/03 6:58:50 PM
8/21/07 6:25:33 AM
|
Clearly BS hates programmers and doesn't trust them
as far as he can throw them. Why else would he work so hard to wrap everything in a straight jacket? Java is kind of that way too but more moderate.
The only thing C++ ought to be used for is purposes for which it was designed. If you're not writing a telephone switching operating system, you don't need it.
I think that it's extraordinarily important that we in computer science keep fun in computing. When it started out, it was an awful lot of fun. Of course, the paying customer got shafted every now and then, and after a while we began to take their complaints seriously. We began to feel as if we really were responsible for the successful, error-free perfect use of these machines. I don't think we are. I think we're responsible for stretching them, setting them off in new directions, and keeping fun in the house. I hope the field of computer science never loses its sense of fun. Above all, I hope we don't become missionaries. Don't feel as if you're Bible salesmen. The world has too many of those already. What you know about computing other people will learn. Don't feel as if the key to successful computing is only in your hands. What's in your hands, I think and hope, is intelligence: the ability to see the machine as more than when you were first led up to it, that you can make it more.
--Alan Perlis
|
Post #75,472
1/18/03 10:58:42 PM
|
Re: Because it's not supposed to be modified...
ChrisR: i'd suspect that it's also not kosher to dereference a Const pointer.
Huh? A pointer you can't dereference isn't much of a pointer, is it.
There's no problem dereferencing a constant pointer. In fact, arrays in C are (in a certain sense) nothing more than a constant pointer.
ChrisR: If a dereference is allowed then the program can backdoor a method to change the value by casting it to another type and then doing an assign.
Isn't that the whole point of casting in C? :-)
-- -- Jim Weirich jweirich@one.net [link|http://w3.one.net/~jweirich|http://w3.one.net/~jweirich] --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
|