Hacker News new | ask | show | jobs
by noyoudumbdolt 1263 days ago
I'm skeptical there's a single C compiler out there that makes the first two behave as expected but not the third. In fact, I wouldn't be surprised if the real oversight is that the standard meant to say all three, or that the authors thought it implied.
1 comments

It's not necessarily up to a compiler, or its program setup stub code, but possibly up to the host environment.

Of course argv is mutable since it's a local variable/param. But what if the pointers are placed, by the OS, into read-only VM pages? Begrudgingly, the string data is made writable though, to conform to the standard.

Please name one platform where this is the case.
Another thing to consider is that the pointers may be writable, but changing them causes harm. E.g. suppose argv[] is prepared by a function which dynamically allocates each pointer, and then the run-time calls free on it when the program exits. According to ISO C, that would be conforming.

I don't know of any platform where there are any ill effects. But the number of platforms out there with C implementations is much larger than my direct experience. Maybe this is just some historic baggage that is overdue for a revision. It was discussed in 1998, but no changes were accepted at the time.

In most coding situations, I probably wouldn't care, the same way I don't care about, say, platforms where for some reason you cannot compare pointers to distinct objects using inequality (another thing not required by ISO C). It's better to break the rules knowingly, though. You want to be badass, not dumbass.