Type of argv parameter of main( )

S

subramanian

In the SECOND EDITION of the book "The C Programming Language - ANSI
C" by K & R,
the following is mentioned:

In page 114, in Section 5.10 "Command-line Arguments", it is mentioned
that argv is a pointer to an array of character strings. Again on the
next page 115, it is mentioned that argv is a pointer to an array of
pointers.

However in the example that follows this statement in this book, the
program is given as mentioned below:

#include <stdio.h>

main(int argc, char *argv[ ] )
{
while (--argc > 0)
printf("%s%s", *++argv, (argc > 1) ? " " : "");

printf("\n");
return 0;
}

MY DOUBT:
 
R

Richard Heathfield

subramanian said:
In the SECOND EDITION of the book "The C Programming Language - ANSI
C" by K & R,
the following is mentioned:

In page 114, in Section 5.10 "Command-line Arguments", it is mentioned
that argv is a pointer to an array of character strings. Again on the
next page 115, it is mentioned that argv is a pointer to an array of
pointers.

Well, close. argv is a pointer to the first element in an array of
pointers.
MY DOUBT:

No, it's not your doubt. It's your question.

If argv is a pointer to array of character strings as mentioned in
these pages, should not the parameter type be char * (*argv)[ ] ?

Yes, if argv were a pointer to an array, the type would indeed be
different. K&R are using terminology very loosely here. In my opinion,
that's a mistake on their part.
 
B

Beej

In page 114, in Section 5.10 "Command-line Arguments", it is mentioned
that argv is a pointer to an array of character strings. Again on the
next page 115, it is mentioned that argv is a pointer to an array of
pointers.

I think they're speaking in the sense that if you have int x[10], x
points to the first element of the array. They could have definitely
been more clear.

It's not correct to say that argv is _of_type_ "pointer to array of
pointers to chars", even though it's true in code that argv points to
the array of pointers to chars.

argv is officially char *argv[] (type array of char*), or char **argv
(type pointer to char*), or the equivalent.

-Beej
 
R

Richard Heathfield

Beej said:

argv is officially char *argv[] (type array of char*),

No, char *argv[], in a formal parameter context, means "argv is a
pointer to pointer to char", not an array of anything. See pp99-100 of
K&R2 for informal verification of this.
 
B

Beej

No, char *argv[], in a formal parameter context, means "argv is a
pointer to pointer to char", not an array of anything. See pp99-100 of
K&R2 for informal verification of this.

I stand corrected.

-Beej
 
M

mark_bluemel

subramanian said:

No, it's not your doubt. It's your question.

I thought we'd already had this discussion. The use of "doubt" to mean
question or perhaps better "uncertainty" is a common usage in "Indian"
English. If, as someone (I think it was Keith T) recently pointed out,
this is an international newsgroup, a little tolerance of variant
English is probably appropriate. There is a difference between the
laziness of "text speak" (u no wht I mn) and someone expressing
themselves in their own idiomatic variant of English.
 
K

Kenny McCormack

I thought we'd already had this discussion. The use of "doubt" to mean
question or perhaps better "uncertainty" is a common usage in "Indian"
English. If, as someone (I think it was Keith T) recently pointed out,
this is an international newsgroup, a little tolerance of variant
English is probably appropriate. There is a difference between the
laziness of "text speak" (u no wht I mn) and someone expressing
themselves in their own idiomatic variant of English.

It is just a pretty good indicator of where you are on the
jag-o-meter. Clearly, and this has been shown many times, RH is further
down the road than is KT. They're both pretty high scorers (on the
jag-o-meter), of course, but RH is further gone.

Or, to put it another way, RH exists to make KT seem at least somewhat
reasonable.
 
C

CBFalconer

I thought we'd already had this discussion. The use of "doubt" to
mean question or perhaps better "uncertainty" is a common usage
in "Indian" English. If, as someone (I think it was Keith T)
recently pointed out, this is an international newsgroup, a
little tolerance of variant English is probably appropriate.
There is a difference between the laziness of "text speak"
(u no wht I mn) and someone expressing themselves in their own
idiomatic variant of English.

In fact, I suspect the majority of the worlds English speakers are
Indian today. If USAnians can use Amerenglish, why can't Indians
use Indenglish? At any rate the only pure English is found in
Canada, eh. :) The real point is that we all have a reasonable
expectation of understanding one another.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
R

Richard Bos

I thought we'd already had this discussion. The use of "doubt" to mean
question or perhaps better "uncertainty" is a common usage in "Indian"
English.

And the use of "loose" to mean "lose" is a common usage in "Internet"
English, but it's equally wrong.
If, as someone (I think it was Keith T) recently pointed out,
this is an international newsgroup, a little tolerance of variant
English is probably appropriate. There is a difference between the
laziness of "text speak" (u no wht I mn) and someone expressing
themselves in their own idiomatic variant of English.

The problem is that "doubt" already means something, and what it does
mean is not "question".

Really. It's just a doubt of educating these people who murder the
English language. (See how stupid that sounds?)

Richard
 
M

mark_bluemel

And the use of "loose" to mean "lose" is a common usage in "Internet"
English, but it's equally wrong.


The problem is that "doubt" already means something, and what it does
mean is not "question".

But it can mean "uncertainty" and I think that, rather than
"question", is what Indian English often means by it.
Really. It's just a doubt of educating these people who murder the
English language. (See how stupid that sounds?)

On the other hand I have a doubt whether or not you were joking in
that sentence.

By the way - what English language do you mean?
 
C

CBFalconer

Richard said:
(e-mail address removed) wrote:
.... snip ...

And the use of "loose" to mean "lose" is a common usage in
"Internet" English, but it's equally wrong.

That is simply a matter of sloppy spelling, assisted by
prononciation variants.
The problem is that "doubt" already means something, and what it
does mean is not "question".

Really. It's just a doubt of educating these people who murder the
English language. (See how stupid that sounds?)

The usage of doubt is perfectly understandable to all. "I have a
doubt" implies the writers uncertainty of his own understanding of
something. Many moons ago I had an English girlfriend who
requested that I "knock me up in the morning". I was willing, but
had second thoughts about the language usage involved.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
K

Kenny McCormack

That is simply a matter of sloppy spelling, assisted by
prononciation variants.


The usage of doubt is perfectly understandable to all. "I have a
doubt" implies the writers uncertainty of his own understanding of
something.

Really, it is just like everything else in this newsgroup.
Pointing out that this usage of "doubt" is wrong (and that it *sounds*
wrong - which is really the point) is entirely correct, but like
pointing out that something isn't in the C standard, ultimately
irrelevant.
 
S

santosh

Really, it is just like everything else in this newsgroup.
Pointing out that this usage of "doubt" is wrong (and that it *sounds*
wrong - which is really the point) is entirely correct, but like
pointing out that something isn't in the C standard, ultimately
irrelevant.

It unlikely that the OP, after having taken the trouble of posting,
would not bother to read the replies, thus missing the chance to get a
"western" perspective on his English. I've observed here instances,
admittedly rare, of posters who've taken note of these types of non-
topical advices.
 
R

Richard Bos

CBFalconer said:
The usage of doubt is perfectly understandable to all. "I have a
doubt" implies the writers uncertainty of his own understanding of
something.

Yah. Of the Queen's English :p

Richard
 

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

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top