473,385 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

elementary construction +1

I'm now looking at page 115 K&R. After having discussed counterexamples, I
shall herewith and henceforth make all my c programs look like

int main(int orange, char* apple[])
{return(0);}

Q1) How large is that int and that char*? (My instinct would be to look at
limits.h, but with the main call, I can't figure out to what extent I'm
%inside% C.)

Q2) The example on 115 completely confuses me. That which is printf'ed
looks like a batch file. How would the output change if the e in echo were
omitted? MPJ
Nov 14 '05 #1
29 1834
Merrill & Michele <be********@comcast.net> scribbled the following:
I'm now looking at page 115 K&R. After having discussed counterexamples, I
shall herewith and henceforth make all my c programs look like int main(int orange, char* apple[])
{return(0);} Q1) How large is that int and that char*? (My instinct would be to look at
limits.h, but with the main call, I can't figure out to what extent I'm
%inside% C.)


It depends what you mean by "large". If you mean how many bytes they
take up, then the sizeof operator is your friend. Try sizeof orange or
sizeof apple.

Question Q2 snipped because I don't have K&R handy at the moment so I
don't know what example you're talking about.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Nothing lasts forever - so why not destroy it now?"
- Quake
Nov 14 '05 #2
Hi there,

I'm now looking at page 115 K&R. After having discussed counterexamples, I
shall herewith and henceforth make all my c programs look like

int main(int orange, char* apple[])
{return(0);}

Q1) How large is that int and that char*? (My instinct would be to look at
limits.h, but with the main call, I can't figure out to what extent I'm
%inside% C.)
Byte: sizeof orange, sizeof *apple
(if you meant apple itself, which equivalently could be declared
as a char **, sizeof apple)

Bit: the above times CHAR_BIT, from <limits.h>

Range: INT_MIN <= orange <= INT_MAX; for pointers, there is no general
pointer range but you are guaranteed a valid range within your
object (that is, apple[0] through apple[orange-1])

Q2) The example on 115 completely confuses me. That which is printf'ed
looks like a batch file. How would the output change if the e in echo were
omitted? MPJ


You are maybe not aware of it but there are translations of K&R to other
languages. For these, the page numbers are not the same. Apart from
that, some of the people who could help you maybe do not even possess
a copy of that book.
It might be better to just copy the example...
Cheers
Michael

Nov 14 '05 #3
> Range: INT_MIN <= orange <= INT_MAX; for pointers, there is no general
pointer range but you are guaranteed a valid range within your
object (that is, apple[0] through apple[orange-1])
That helps. I know that I can use sizeof for my implementation and
determine what holds for my machine. I'm trying to think of a way never to
get stung by a machine whose INT_MIN and INT_MAX I haven't accounted for.
The only thing I can think of right now is to pass argv [] to a
similar-sized matrix with fields the size of INT_MAX.
You are maybe not aware of it but there are translations of K&R to other
languages. For these, the page numbers are not the same. Apart from
that, some of the people who could help you maybe do not even possess
a copy of that book.
It might be better to just copy the example...


Dass unsre Bible nicht Eurer Bibel entspricht ist mir nicht eingefallen. Es
folgt K&R, zweite Ausgabe §5.10 dritter Absatz:

#include <stdio.h>
main(int argc, char *argv[])
{
int i;

for (i=1; i < argc; i++)
print f("%s%s", *++argv[i]; (i < argc-1) ? " " : "");
printf("\n");
return 0;
}

Wir waren neulich bei Euch. Eure Gastfreundschaft ist legendaer. MPJ
Nov 14 '05 #4
Merrill & Michele wrote:
#include <stdio.h>
main(int argc, char *argv[])
{
int i;

for (i=1; i < argc; i++)
print f("%s%s", *++argv[i]; (i < argc-1) ? " " : "");
printf("%s%s", argv[i], i < argc - 1 ? " " : "");
printf("\n");
return 0;
}

#include <stdio.h>
main(int argc, char *argv[])
{
while (*++argv != NULL) {
printf("%s ", *argv);
}
putchar('\n');
return 0;
}

Under what conditions does the intial value of argc equal zero?

--
pete
Nov 14 '05 #5
Groovy hepcat Merrill & Michele was jivin' on Fri, 24 Sep 2004
12:41:20 -0500 in comp.lang.c.
elementary construction +1's a cool scene! Dig it!
I'm now looking at page 115 K&R. After having discussed counterexamples, I
shall herewith and henceforth make all my c programs look like

int main(int orange, char* apple[])
{return(0);}
Um..., OK.
Q1) How large is that int and that char*? (My instinct would be to look at
What char*? I don't see any char*. I see a char**. Sure it's
disguised as a char*[], but it's a char** alright. But I see no char*.
limits.h, but with the main call, I can't figure out to what extent I'm
%inside% C.)
What? That doesn't make sense. I have no idea what you're trying to
say.
Q2) The example on 115 completely confuses me. That which is printf'ed
Which one? There are two examples on page 115 (of my copy of K&R
anyhow).
looks like a batch file. How would the output change if the e in echo were
omitted? MPJ


What? What looks like a batch file? What sort of batch file? You
mean a DOS batch language file? In what way does it look like that?
What the hell have you been smoking? What e in what echo?
Oh, I think I see what you mean. On page 114 an example input is
given: "echo hello, world". Actually, the "echo" part is not the input
at all. It's the name of the program. Typing "echo hello, world" at a
command prompt would cause the program echo to output "hello, world".
The two code examples on page 115 are different versions of this echo
program.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Nov 14 '05 #6
Cheerio,

Range: INT_MIN <= orange <= INT_MAX; for pointers, there is no general
pointer range but you are guaranteed a valid range within your
object (that is, apple[0] through apple[orange-1])
That helps. I know that I can use sizeof for my implementation and
determine what holds for my machine. I'm trying to think of a way never to
get stung by a machine whose INT_MIN and INT_MAX I haven't accounted for.
The only thing I can think of right now is to pass argv [] to a
similar-sized matrix with fields the size of INT_MAX.


Umh, I do not have the least clue what you are talking about.
argc is either the number of arguments to the program call (including
the program name) or zero. In the first case, I can hardly think
of a program call taking 2^15-1 arguments, aside from the fact that
you probably do not get the command line into the buffer on some
systems. And you really do not want to have a typo or left-out
argument...

Maybe the process of getting from the command line to argc and argv
is not clear to you. I will give a very simple example of how they
_could_ be obtained:
- The shell gets a line and reads to the first white space.
It might use strtok() to put in a '\0' there. Then it looks in
the search path whether it can find an executable of that name.
- If it does, it runs through the rest of the command line obtaining
the number of non-white-space areas (that is, arguments).
- It allocates space for enough char * variables to point to the
start of each argument, that is: argv.
- It runs through the command line and points argv[i++] to the beginning
of the next parameter. Usually you combine that with strtok() to get
in the '\0' after the argument.
- Now, we have the command line still in the same place in memory
but interspersed with several '\0', thus making it into many strings.
argv[i] just contains a pointer to the (i+1)th argument.

You are maybe not aware of it but there are translations of K&R to other
languages. For these, the page numbers are not the same. Apart from
that, some of the people who could help you maybe do not even possess
a copy of that book.
It might be better to just copy the example...


Dass unsre Bible nicht Eurer Bibel entspricht ist mir nicht eingefallen. Es
folgt K&R, zweite Ausgabe §5.10 dritter Absatz:

#include <stdio.h>
main(int argc, char *argv[])
{
int i;

for (i=1; i < argc; i++)
printf("%s%s", *++argv[i]; (i < argc-1) ? " " : "");
printf("\n");
return 0;
}


Hmmm, okay. That does not tell me anything about the echo you have
been asking for. If I understand the posting of Peter Shaggy Haywood
correctly, echo seems to be the name of the program, usually pointed
to by argv[0] if argc>=1. Making this cho would not help as the
program could not be found (of course you could rename it to cho but
that is beside the point.

Is the rest of the program clear to you?

Wir waren neulich bei Euch. Eure Gastfreundschaft ist legendaer.


Pleasant to hear; I was not aware that German hospitality is that
good...
HTH
Michael

Nov 14 '05 #7
Thanks all for your replies. While my question revealed glaring ignorance,
which was so amply discussed, the thrust of the question dealt with exactly
what argv[] was pointing to. Now that I'm three days wiser, it seems that
argv[0] points to a string with the path and program name in it. "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. argv[argc]
points to null. My thinking that I needed to determine the sizes of these
pointers was fundamentally wrong-headed. Who cares how large they are when
you have argc+1 to tell you how many there are.

As for the root of misunderstanding, I am going to cast aspersion on my
implementation. Finally, I'll run Pete's program soon here, as it is likely
quite helpful. Again, thanks all. MPJ
Nov 14 '05 #8
Merrill & Michele wrote:
Now that I'm three days wiser, it seems that
argv[0] points to a string with the path and program name in it.
It does if argc is positive. What if argc is zero?
Who cares how large they are when
you have argc+1 to tell you how many there are.
(argc + 0) is how many pointers to strings you have.
(argc - 1) is how many parameters you have.
Finally, I'll run Pete's program soon here, as it is likely
quite helpful.


I think that program is missing some code to guard against the
(argc == 0) case.

N869
5.1.2.2.1 Program startup
[#2] If they are declared, the parameters to the main
function shall obey the following constraints:
-- The value of argc shall be nonnegative.
-- argv[argc] shall be a null pointer.
-- If the value of argc is greater than zero, the array
members argv[0] through argv[argc-1] inclusive shall
contain pointers to strings, which are given
implementation-defined values by the host environment
prior to program startup. The intent is to supply to
the program information determined prior to program
startup from elsewhere in the hosted environment. If
the host environment is not capable of supplying
strings with letters in both uppercase and lowercase,
the implementation shall ensure that the strings are
received in lowercase.
-- If the value of argc is greater than zero, the string
pointed to by argv[0] represents the program name;
argv[0][0] shall be the null character if the program
name is not available from the host environment. If
the value of argc is greater than one, the strings
pointed to by argv[1] through argv[argc-1] represent
the program parameters.
-- The parameters argc and argv and the strings pointed to
by the argv array shall be modifiable by the program,
and retain their last-stored values between program
startup and program termination.

--
pete
Nov 14 '05 #9
In <41**********@mindspring.com> pete <pf*****@mindspring.com> writes:
Under what conditions does the intial value of argc equal zero?


The program was started with no parameters and its name is not available.
Or the implementation simply does not *meaningfully* support the argc/argv
mechanism:

- argv[argc] shall be a null pointer.

- If the value of argc is greater than zero, the array members
argv[0] through argv[argc-1] inclusive shall contain pointers
to strings,...

- If the value of argc is greater than zero, the string pointed
to by argv[0] represents the program name;...

An implementation where argc is *always* zero and argv[0] is a null
pointer trivially satisfies all these requirements.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #10

In article <vv********************@comcast.com>, "Merrill & Michele" <be********@comcast.net> writes:
it seems that
argv[0] points to a string with the path and program name in it.
argv[0], if argc > 0, will either be an empty string or the "program
name", which can be whatever the implementation wants it to be. (OT:
on Unix, for example, argv[0] will be whatever string was passed as
the appropriate parameter to one of the exec system calls. That may
be the name of the executable image, and it may have a relative or
absolute path prefixed to it, but in many cases it is not and does
not.)

Many C programs can assume that argv[0] (if argc > 0 and argv[0] is
not an empty string) is suitable to use as the "program name" for
purposes such as labelling messages. For anything beyond that it's
a good idea to examine the contents of argv[0] and apply some
heuristics to see that it appears to be of the form you expect, and
that your code won't do anything wrong with its contents. For
example, don't assume there's any path information (eg by using the
results of the strrchr function to "skip over" the path, without
checking to see if it failed). Don't assume that the contents of
argv[0] are of a reasonable length. And so forth.
"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.
You have that backward, if it applies at all. "echo" was a poor name
for an MS-DOS keyword, since it was already used in K&R, which predates
DOS.

A more reasonable statement would be that neither K&R nor MS-DOS have
any exclusive right to the name "echo", and people reading the former
need to avoid making assumptions conditioned by inapplicable domains,
such as what they know of the latter.
argv[argc]
points to null. My thinking that I needed to determine the sizes of these
pointers was fundamentally wrong-headed. Who cares how large they are when
you have argc+1 to tell you how many there are.


And you have argv[argc] to tell you when you've reached the end of
the list, so argc is just frosting on the cake.

--
Michael Wojcik mi************@microfocus.com

Not the author (with K.Ravichandran and T.Rick Fletcher) of "Mode specific
chemistry of HS + N{_2}O(n,1,0) using stimulated Raman excitation".
Nov 14 '05 #11

In article <41**********@mindspring.com>, pete <pf*****@mindspring.com> writes:

Under what conditions does the intial value of argc equal zero?


Is that a rhetorical question? Under whatever conditions please the
implementation, of course, since the standard only guarantees that
argc be non-negative in a hosted implementation, and not even that in
a freestanding one.

argv might be 0 always, or on Thursdays, or if the program is invoked
in a certain fashion. (The last is true on all POSIX systems, for
example.)

--
Michael Wojcik mi************@microfocus.com

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
-- David Bonde
Nov 14 '05 #12
Dan Pop wrote:

In <41**********@mindspring.com> pete <pf*****@mindspring.com> writes:
Under what conditions does the intial value of argc equal zero?
The program was started with no parameters
and its name is not available.


I know how a program can be started with no parameters,
but besides what you wrote next here:
Or the implementation simply does not
*meaningfully* support the argc/argv mechanism:


I can't think of what else
could cause the program name to be unavailable.

--
pete
Nov 14 '05 #13
pete wrote:
Dan Pop wrote:
.... snip ...
Or the implementation simply does not
*meaningfully* support the argc/argv mechanism:


I can't think of what else
could cause the program name to be unavailable.


The shell, or whatever OS operation loads the program, simply
fails to make it available. By the time the program begins
execution it is simply a mass of loaded code in memory.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 14 '05 #14
CBFalconer wrote:

pete wrote:
Dan Pop wrote:

... snip ...
Or the implementation simply does not
*meaningfully* support the argc/argv mechanism:


I can't think of what else
could cause the program name to be unavailable.


The shell, or whatever OS operation loads the program, simply
fails to make it available. By the time the program begins
execution it is simply a mass of loaded code in memory.


And you consider that behavior to be within the parameters
of an implementation that *does meaningfully*
support the argc/argv mechanism?

--
pete
Nov 14 '05 #15
In <41***********@mindspring.com> pete <pf*****@mindspring.com> writes:
Dan Pop wrote:

In <41**********@mindspring.com> pete <pf*****@mindspring.com> writes:
>Under what conditions does the intial value of argc equal zero?


The program was started with no parameters
and its name is not available.


I know how a program can be started with no parameters,
but besides what you wrote next here:
Or the implementation simply does not
*meaningfully* support the argc/argv mechanism:


I can't think of what else
could cause the program name to be unavailable.


A lazy Unix programmer didn't bother to provide it when invoking his
favourite exec function to execute the program. Not all programs are
started by one well behaved shell or another. The same mechanism is
used to give arbitrary names to programs.

On certain translation environments there is no obvious program name as
neither the source code nor the executable code resides on an external
file (everything is in memory).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #16
In <41***********@mindspring.com> pete <pf*****@mindspring.com> writes:
CBFalconer wrote:

pete wrote:
> Dan Pop wrote:
>>

... snip ...
>
>> Or the implementation simply does not
>> *meaningfully* support the argc/argv mechanism:
>
> I can't think of what else
> could cause the program name to be unavailable.


The shell, or whatever OS operation loads the program, simply
fails to make it available. By the time the program begins
execution it is simply a mass of loaded code in memory.


And you consider that behavior to be within the parameters
of an implementation that *does meaningfully*
support the argc/argv mechanism?


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...

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #17
pete wrote:
CBFalconer wrote:
pete wrote:
Dan Pop wrote:

... snip ...

Or the implementation simply does not
*meaningfully* support the argc/argv mechanism:

I can't think of what else
could cause the program name to be unavailable.


The shell, or whatever OS operation loads the program, simply
fails to make it available. By the time the program begins
execution it is simply a mass of loaded code in memory.


And you consider that behavior to be within the parameters
of an implementation that *does meaningfully* support the
argc/argv mechanism?


Yes

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Nov 14 '05 #18

In article <41***********@mindspring.com>, pete <pf*****@mindspring.com> writes:
CBFalconer wrote:

pete wrote:
Dan Pop wrote:

I can't think of what else
could cause the program name to be unavailable.


The shell, or whatever OS operation loads the program, simply
fails to make it available. By the time the program begins
execution it is simply a mass of loaded code in memory.


And you consider that behavior to be within the parameters
of an implementation that *does meaningfully*
support the argc/argv mechanism?


Yes. In fact, that's how it worked in the first C implementation
that supported argc/argv at all - the original Unix one. And that's
how it continues to work on Unix.

On Unix, whatever causes the program to be executed gets to decide
the entire contents of argv (which in turn decide the value of argc).
That's a central aspect of the execv system call, which in turn is a
core part of the OS. It's quite important to how essentially all
Unix C implementations behave, and a number of programs make use of
it.

So not only is it meaningful, it has a better pedigree than any other
behavior for argc/argv. This isn't one of those "never seen in a
real implementation" cases that occasional visitors to comp.lang.c
like to moan about. Assuming argc > 0 is not a good idea.

--
Michael Wojcik mi************@microfocus.com

The history of Namco begins in 1955 when the Company's predecessor
began operating rocking-horse rides on the rooftop of a department
store in Yokohama. Since then, we have pioneered diverse forms of
amusement and entertainment that help people live their dreams. As
we approach the 21st century, an "Era of Spirituality", Namco will
help to spread dynamic entertainment throughout the world.
-- video game producer Namco's English-language Japanese web page
Nov 14 '05 #19
> argv[0], if argc > 0, will either be an empty string or the "program
name", which can be whatever the implementation wants it to be. (OT:
on Unix, for example, argv[0] will be whatever string was passed as
the appropriate parameter to one of the exec system calls. That may
be the name of the executable image, and it may have a relative or
absolute path prefixed to it, but in many cases it is not and does
not.)

Many C programs can assume that argv[0] (if argc > 0 and argv[0] is
not an empty string) is suitable to use as the "program name" for
purposes such as labelling messages. For anything beyond that it's
a good idea to examine the contents of argv[0] and apply some
heuristics to see that it appears to be of the form you expect, and
that your code won't do anything wrong with its contents. For
example, don't assume there's any path information (eg by using the
results of the strrchr function to "skip over" the path, without
checking to see if it failed). Don't assume that the contents of
argv[0] are of a reasonable length. And so forth.


Good tips.

"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.


You have that backward, if it applies at all. "echo" was a poor name
for an MS-DOS keyword, since it was already used in K&R, which predates
DOS.

A more reasonable statement would be that neither K&R nor MS-DOS have
any exclusive right to the name "echo", and people reading the former
need to avoid making assumptions conditioned by inapplicable domains,
such as what they know of the latter.


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? At the risk of giving offense, I don't think it too off-base
to look at K&R as the first five books of Moses: extraordinarily important
for, say, pedagogy and exegetics, but not the final word in the modern
world. MPJ
Nov 14 '05 #20
Dan Pop wrote:

In <41***********@mindspring.com> pete <pf*****@mindspring.com> writes:
CBFalconer wrote:

pete wrote:
> Dan Pop wrote:
>>
... snip ...
>
>> Or the implementation simply does not
>> *meaningfully* support the argc/argv mechanism:
>
> I can't think of what else
> could cause the program name to be unavailable.

The shell, or whatever OS operation loads the program, simply
fails to make it available. By the time the program begins
execution it is simply a mass of loaded code in memory.


And you consider that behavior to be within the parameters
of an implementation that *does meaningfully*
support the argc/argv mechanism?


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.

--
pete
Nov 14 '05 #21
This is mostly an aside (or two), but:

In article <news:vv********************@comcast.com>
Merrill & Michele <be********@comcast.net> wrote:
... "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.).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #22
In <rt********************@comcast.com> "Merrill & Michele" <be********@comcast.net> writes:
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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #23
Chris Torek <no****@torek.net> writes:
Merrill & Michele <be********@comcast.net> wrote:
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;
--
Ben Pfaff
email: bl*@cs.stanford.edu
web: http://benpfaff.org
Nov 14 '05 #24

In article <rt********************@comcast.com>, "Merrill & Michele" <be********@comcast.net> writes:

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 mi************@microfocus.com

"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_
Nov 14 '05 #25
MPJ wrote:
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...)

--
Michael Wojcik


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
Nov 14 '05 #26

On Sun, 3 Oct 2004, Merrill & Michele wrote:

MPJ wrote:
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
Nov 14 '05 #27
> > MPJ wrote:
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.
MPJ wrote:
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


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
Nov 14 '05 #28
Arthur J. O'Dwyer <aj*@nospam.andrew.cmu.edu> wrote:

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.

Nov 14 '05 #29
On Sun, 17 Oct 2004 19:56:14 -0000, in comp.lang.c , Benjamin Ketcham
<bk******@drizzle.com> wrote:
Arthur J. O'Dwyer <aj*@nospam.andrew.cmu.edu> wrote:

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.


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

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Anthony | last post by:
Hi, Can anyone help me out here, I'm looking for a design (pattern?) for a-synchronic construction of a class. I need this design in a framework which will run in a multithreaded system. I...
2
by: Steve | last post by:
Hi Folks, Sorry for this stupid question, but how do you handle errors during class construction. In other words, if I have a class that loads a file, and during loading, an error occurs, how do...
14
by: trying_to_learn | last post by:
i am on the chapter on copy construction in C++ in the code (see below), the author says if u pass the object by value as in HowMany h2 = f(h); ....then a bitwise object is created w/o calling...
5
by: Lionel B | last post by:
Greetings, I am trying to implement "element-wise" arithmetic operators for a class along the following lines (this is a simplified example): // ----- BEGIN CODE ----- struct X { int a,b;
0
by: Geoffrey L. Collier | last post by:
I wrote a bunch of code to do elementary statistics in VB, and would prefer to find code in C# to recoding all of the VB code. A search of the web found very little. Does anyone know of a good...
8
by: pauldepstein | last post by:
I am writing a program which looks at nodes which have coordinates which are time-dependent. So I have a class called node which contains the private member declarations int date; int month; ...
5
by: bromio | last post by:
can someone help me to make code for digital clock using AT89S52. The specs of clock are 12 hour clock,am-pm display,use timer interrupts to have delay.two external inputs to adjust hours and...
7
by: BeautifulMind | last post by:
In case of inheritence the order of execution of constructors is in the order of derivation and order of destructor execution is in reverse order of derivation. Is this case also true in case...
15
by: Victor Bazarov | last post by:
Hello, Take a look at this program: ----------------------------------- class B { B(const B&); B& operator=(const B&); public: B(int);
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.