elementary construction +1

P

pete

Dan said:
Since it comes from *outside* the implementation, there is nothing the
implementation itself can do about it. All the implementation can do
is obtain this information from the execution environment and make it
available to the program. If the execution environment refuses to
provide the information...

Thank you.
 
C

Chris Torek

This is mostly an aside (or two), but:

... "Echo", by the way, is a terrible name to call the program
on K&R 115 because the person working up his C game has to unlearn
a lot of DOS.

The name comes from the original White Book, printed in 1978. (I
bought it in 1981 for $15. Remember when computer books were under
$30? :) ) As such, it predates DOS. Perhaps they should have
changed it for K&R2 anyway.

This line is the real reason I am posting, though:
argv[argc] points to null.

In my opinion, it is much better to say (and think) "is null" than
"points to null". Given any appropriate type T, the value (T *)NULL
-- the null pointer of type "pointer to T" -- does not point *to*
any valid C object (or function, if T is a function type) at all.
Saying "points to null" will eventually lead you into a trap -- or
at least, I have seen this happen before with others.

There is a lot more verbiage on this topic in the comp.lang.c FAQ (q.v.).
 
D

Dan Pop

In said:
I almost hate to bring up a sentence in paragraph 2 §5.10: "By convention,
argv[0] is the name by which the program was invoked, so argc is at least
1."

Pay special attention to the first two words: "By convention". If
someone is breaking this convention, the rest of the sentence does not
apply.

Dan
 
B

Ben Pfaff

Chris Torek said:
Merrill & Michele said:
argv[argc] points to null.

In my opinion, it is much better to say (and think) "is null" than
"points to null". [...]

This is especially true because there are legitimate, but
distinct, circumstances in which a pointer really does point to
null. For example, below, p is null, but pp points to null:
void *p = NULL;
void **pp = &p;
 
M

Michael Wojcik

I almost hate to bring up a sentence in paragraph 2 §5.10: "By convention,
argv[0] is the name by which the program was invoked, so argc is at least
1." Doesn't that say something about the relevance of K&R to the argc==0
thread above?

Sure, but note that on Unix - where C was first used - that
convention is subject to the whim of the programmer who executes the
program in the first place. (In fact, this is a common mistake made
by new Unix programmers - they invoke a program with no arguments at
all because they assume the environment will provide argv[0] for
them.)

Obviously, Dennis Ritchie knew perfectly well how the execv system
call worked in Unix when he co-wrote K&R, so he knew that programs
couldn't depend on argv[0] being set. But the C / Unix mindset of
the 1970s was largely a "best effort" one: let's get some work done,
and if we have to assume some error conditions are sufficiently rare
that we'll let the program crash if they happen, so be it.
(Ritchie's comment on the SIGPIPE signal is a good example: SIGPIPE
was invented so that pipelines would work correctly even if programs
didn't check for error returns when writing to standard output.)

So indeed it's just that: a convention, and the truly robust program
should assume that some rude invoker might violate it. The quick-
and-dirty program, tossed together for a single use, probably needn't
bother. (Though most programmers have seen at least a few of those
quick-and-dirty, temporary programs get distributed and come back to
plague them later...)

--
Michael Wojcik (e-mail address removed)

"Well, we're not getting a girl," said Marilla, as if poisoning wells were
a purely feminine accomplishment and not to be dreaded in the case of a boy.
-- L. M. Montgomery, _Anne of Green Gables_
 
M

Merrill & Michele

MPJ said:
I almost hate to bring up a sentence in paragraph 2 §5.10: "By convention,
argv[0] is the name by which the program was invoked, so argc is at least
1." Doesn't that say something about the relevance of K&R to the argc==0
thread above?

"Michael Wojcik" wrote >
Sure, but note that on Unix - where C was first used - that
convention is subject to the whim of the programmer who executes the
program in the first place. (In fact, this is a common mistake made
by new Unix programmers - they invoke a program with no arguments at
all because they assume the environment will provide argv[0] for
them.)

Obviously, Dennis Ritchie knew perfectly well how the execv system
call worked in Unix when he co-wrote K&R, so he knew that programs
couldn't depend on argv[0] being set. But the C / Unix mindset of
the 1970s was largely a "best effort" one: let's get some work done,
and if we have to assume some error conditions are sufficiently rare
that we'll let the program crash if they happen, so be it.
(Ritchie's comment on the SIGPIPE signal is a good example: SIGPIPE
was invented so that pipelines would work correctly even if programs
didn't check for error returns when writing to standard output.)

So indeed it's just that: a convention, and the truly robust program
should assume that some rude invoker might violate it. The quick-
and-dirty program, tossed together for a single use, probably needn't
bother. (Though most programmers have seen at least a few of those
quick-and-dirty, temporary programs get distributed and come back to
plague them later...)

I find this interesting and topical, even though it's on the end of a thread
that next to no one is looking at. Is, however, Unix considered to be an
implementation or is it above reproach as such, because it gave immaculate
birth? MPJ
 
A

Arthur J. O'Dwyer

I almost hate to bring up a sentence in paragraph 2 §5.10: "By
convention, argv[0] is the name by which the program was invoked, so
argc is at least 1."

"Michael Wojcik" wrote >
Sure, but note that on Unix - where C was first used - that
convention is subject to the whim of the programmer who executes the
program in the first place.
[snip]

I find this interesting and topical, even though it's on the end of a thread
that next to no one is looking at. Is, however, Unix considered to be an
implementation or is it above reproach as such, because it gave immaculate
birth? MPJ

Unix is an "environment," not an "implementation." (At least, it's not
an "implementation" of ISO C.) There do exist plenty of C implementations
that run in the Unix environment, though: e.g., gcc. Unix is just as
reasonable a platform for C implementations as MS-DOS or OS 9.

I agree with Michael's conclusion: the K&R passage you quoted was aimed
at making sure newbies understood the basic purpose and use of 'argv', not
at explaining all the technical details. In Standard-speak, K&R is
"informative," not "normative," and you shouldn't take everything it says
as 100% true of standard C. 95% true, maybe, and useful regardless. :)

-Arthur
 
M

Merrill & Michele

MPJ said:
I almost hate to bring up a sentence in paragraph 2 §5.10: "By
convention, argv[0] is the name by which the program was invoked, so
argc is at least 1."

"Michael Wojcik" wrote >
Sure, but note that on Unix - where C was first used - that
convention is subject to the whim of the programmer who executes the
program in the first place.
Arthur J. O'Dwyer" wrote:
Unix is an "environment," not an "implementation." (At least, it's not
an "implementation" of ISO C.) There do exist plenty of C implementations
that run in the Unix environment, though: e.g., gcc. Unix is just as
reasonable a platform for C implementations as MS-DOS or OS 9.

I agree with Michael's conclusion: the K&R passage you quoted was aimed
at making sure newbies understood the basic purpose and use of 'argv', not
at explaining all the technical details. In Standard-speak, K&R is
"informative," not "normative," and you shouldn't take everything it says
as 100% true of standard C. 95% true, maybe, and useful regardless. :)

-Arthur

Thank you for your reply. (I think I failed to thank Mr. Wojcik for his.)

Q1) How does this go over: Resolved, Unix is a platform, a black box
containing compiled code, on top of which the C language operates.

Q2) How does this go over: In clc, implementations are OT. gcc is an
implementation. Therefore, gcc is, qua implementation, OT.

It's far OT for me to comment on the word "normative." I'll simply #define
normative binding . MPJ
 
B

Benjamin Ketcham

Arthur J. O'Dwyer said:
Unix is just as
reasonable a platform for C implementations as MS-DOS

In the same sense that a Ferrari is just as reasonable a platform
for driving fast as a bulldozer.
 
M

Mark McIntyre

In the same sense that a Ferrari is just as reasonable a platform
for driving fast as a bulldozer.

And your C point was?
This is not comp.unix.advocacy.
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top