Re: Is argv array modifiable ?
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 15 Dec 2005 23:58:17 +0000
bluejack wrote:
Peter Nilsson wrote:That is a naive, even dangerous, form of reasoning. C has many quirks which are counter-intuitive. Some of them are far from sensisble, e.g. gets.
Granted.
These quirks won't be learnt by trial and error. The *most* you will learn is how the specific version of the specific implementation you are using works.
Trusting (or blaming) the Committee is an irrelevance. At the end of the day, the language is that written in the Standard. It is up to programmers to educate themselves on what that language is.
And, while there are several good approaches to educating yourself on what the language is ... and I realize this is going to endear me to nobody ... my preferred method is "trial and error" -- despite my "naive and dangerous" form of reasoning, it's a perfectly effective approach,
No, it is most definitely NOT a perfectly effective method. All sorts of things that you might think are correct, and might work on your compiler this week, might fail abysmally when it actually matters to you.
> assuming you start out by trusting nobody.
Start by not trusting trial and error, because it has been repeatedly been shown that the people posting here having relied on it to learn C have learnt to do things which are definitely wrong.
> I don't trust
the standard (in part because there's no guarantee it has been implemented correctly,
In that case build your own chip factory, design and build your own chips, and write your own compiler.
> but mostly because I don't have a copy),
Google for n1124.pdf to get a free public draft of the next version, or buy a copy of the current version from a standards body (you can get it for $18 last I heard).
I don't trust compiler designers (because they don't necessarily implement correctly),
In that case don't use any you have not implemented. You also can't trust assemblers, text editors or the OS by that reasoning.
> I don't trust secondary documentation (it's
like a photocopy of a photocopy),
It is easy to find reviews of books to see if they are reliable, and you can cross-reference to the standard if you are not sure.
> I *certainly* don't trust usenet,
and I trust my own memory *least of all*.
> What I trust are demonstrable
results.
I can demonstrate with one compiler that you can safely modify string literals and get the expected result. I can also demonstrate with a later version of the *same* compiler that you can't modify string literals because it causes a SIGSEGV (I might be wrong on the exact signal, but definitely a crash). The reality is that anything can happen because it is undefined behaviour. However, had I relied on your method of trial and error all my code could have suddenly gone from "working" to "crashing".
If I could be bothered I could come up with lots of other examples, but the above is one I know to be demonstrably true.
Naturally, with that mentality, I tend to code defensively.
Coding defensively REQUIRES understanding how the language is DEFINED to work, what you are doing by relying on trial and error rather than a reliable source of information is coding stupidly.
> It would
never even occur to me to *want* to change argv (or use gets). Still I do find these conversations fascinating, and I always enjoy the cranky attitude found on usenet!
Well, if you think trial and error is a substitute for a good text book expect responses a lot more cranky than mine.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.
- References:
- Is argv array modifiable ?
- From: mnaydin
- Re: Is argv array modifiable ?
- From: Richard Heathfield
- Re: Is argv array modifiable ?
- From: Jordan Abel
- Re: Is argv array modifiable ?
- From: Eric Sosman
- Re: Is argv array modifiable ?
- From: bluejack
- Re: Is argv array modifiable ?
- From: Peter Nilsson
- Re: Is argv array modifiable ?
- From: bluejack
- Is argv array modifiable ?
- Prev by Date: Internationalization - Unicode - Format used for command line arguments?
- Next by Date: Re: Operational and functional differences - #define vs typedef ?
- Previous by thread: Re: Is argv array modifiable ?
- Next by thread: Re: Is argv array modifiable ?
- Index(es):
Relevant Pages
|
|