Array vs Vector

R

Richard Tobin

Martin Ambuhl said:
What appear to be multi-dimensional arrays in C are (1-dimensional)
arrays of (1-dimensional) arrays of ... to however many 'dimensions' are
being considered, or vectors of vectors of ....

But they are also multi-dimensional arrays, unless section 6.5.2.1
(Array subscripting) of C99 is mistaken.

-- Richard
 
R

Richard Tobin

What do you think the v there is for? :)
[/QUOTE]

Good try, but it's pretty clearly "vector". It matches "execv", and
the oldest man page for that I have to hand (6th edition) refers to
both "a vector of strings" and "an array of character pointers", and
in the assembler section to a "list".

(It also says that argv[argc] is -1, which has changed.)

-- Richard
 
C

CBFalconer

.... snip ...

If you are talking about

std::vector<int> a;
vs.
int a[10];

there are big differences between the two. ...

Indeed. The first doesn't exist. The second declares a to be an
array of 10 ints. Bear in mind that this is c.l.c, where we
discuss the C language.
 
C

CBFalconer

viza said:
Nonsense, the term is used in almost every C program ever written:

main( int argc, char **argv )

What do you think the v there is for? :)

It distinguishes the name of the object (a parameter) from the name
of the other parameter, which is argc. If you wish you can replace
those names by x and y, or anything else unique, with no alteration
to the program.
 
K

Keith Thompson

CBFalconer said:
It distinguishes the name of the object (a parameter) from the name
of the other parameter, which is argc. If you wish you can replace
those names by x and y, or anything else unique, with no alteration
to the program.

Of course, but that's hardly the point, is it? argc and argv are the
conventional names for the two parameters of main(). I'm fairly sure
that the names originated as abbreviations of "argument count" and
"argument vector".
 
J

James Harris

Nonsense, the term is used in almost every C program ever written:

main( int argc, char **argv )

What do you think the v there is for? :)

Well, it looks like you are right - or at least more right than the
four people so far who have chosen to argue against your suggestion.
Of course it's hard to be dogmatic as the name is only a convention
but here are two sources that support what you say. First the glossary
at

http://www.c-faq.com/sx1/

calls argv an "array ('vector') of command-line arguments."

(By the way, is this the current C FAQ? I couldn't see any recent
periodic posts to c.l.c telling people where to find the FAQ.)

Second, K&R 2nd ed in sect 5.10 says the second parameter is named
"argv, for argument vector."

Speaking of arguments I think you've won this one. :)

James
 
V

viza

Hi

Second, K&R 2nd ed in sect 5.10 says the second parameter is named
"argv, for argument vector."

Being a fully-bearded physicist (like both Kernighan & Ritchie) I just
instinctively read it as "vector".

viza
 
F

Flash Gordon

James Harris wrote, On 05/12/08 00:51:

http://www.c-faq.com/sx1/

calls argv an "array ('vector') of command-line arguments."

(By the way, is this the current C FAQ? I couldn't see any recent
periodic posts to c.l.c telling people where to find the FAQ.)

<snip>

Yes, c-faq.com is the current location of the FAQ. Steve recommends
using the link http://www.c-faq.com/ as everything else is subject to
change (although I don't think it has changed since he announced it).
 
C

CBFalconer

Richard said:
CBFalconer said:
.... snip ...


Er, yes it does.
.... snip ...

You appear to believe that "not discussed on comp.lang.c" and
"doesn't exist" are isomorphic. Finding food must be a real
problem for you.

I have this peculiar (to you, apparently) habit of searching for
food in grocery stores or restaurants, rather than hardware stores,
bicycle factories, etc. Similarly I do not search for C++
information on c.l.c. Most of the users here have the capability
of extending questions and answers in such a manner as to be
topical. If you try that, you might find that things make more
sense. You will certainly reduce the amount of useless drivel you
generate.
 
K

Keith Thompson

CBFalconer said:
I have this peculiar (to you, apparently) habit of searching for
food in grocery stores or restaurants, rather than hardware stores,
bicycle factories, etc. Similarly I do not search for C++
information on c.l.c. Most of the users here have the capability
of extending questions and answers in such a manner as to be
topical. If you try that, you might find that things make more
sense. You will certainly reduce the amount of useless drivel you
generate.

If you're standing in a hardware store, and somebody asks you where to
find the potatoes, do you tell him that potatoes don't exist?

Continuing with the metaphor, Richard did not say or imply that one
should look for potatoes in a hardware store, merely that a claim that
potatoes don't exist is false regardless of where you're standing when
you make it.
 
J

jameskuyper

CBFalconer said:
I have this peculiar (to you, apparently) habit of searching for
food in grocery stores or restaurants, rather than hardware stores,
bicycle factories, etc.

No, what is peculiar is your habit of doing the equivalent of
declaring that there's no such thing as food, just because you happen
to currently be in a hardware store. If you said that there was no
food "here" that would be a little bit better (though it doesn't take
into consideration the point of view of termites and carnivores, for
whom the typical hardware store is full of food - aka wood and
customers, respectively). You'd be more correct if you said "there's
no food for sale here". But that would have corresponded to you saying
"std::vector does not exist in C", a statement you didn't make.
Instead, you terminated the statement before saying "in C", converting
what could have been a perfectly true statement into a patently false
one.

It's perfectly true that the topic of this newsgroup is C; but anyone
who knows sufficiently little about the differences between C and C++
that they need to be told that std::vector does not exist in C, is
unlikely to guess that there was an implicit "in C" missing from your
statement. If they know that it does exist (in C++), they're just
going wonder what kind of nutcase you who would spouting nonsense like
that. Wording your statement the way you did prevents it from being
useful to anyone who actually needs to know what you tried, but
failed, to communicate.
 
J

James Harris

... snip ...



... snip ...


I have this peculiar (to you, apparently) habit of searching for
food in grocery stores or restaurants, rather than hardware stores,
bicycle factories, etc. Similarly I do not search for C++
information on c.l.c. Most of the users here have the capability
of extending questions and answers in such a manner as to be
topical. If you try that, you might find that things make more
sense. You will certainly reduce the amount of useless drivel you
generate.

[OT] Eloquently put, Chuck. There's something about programming that
makes pedants of us all. Or maybe a pre-existing pedantic mind-set
predisposes one to programming. Perhaps the more pedantic head for the
lower level languages.

To continue Richard's and your food analogy:


we argue over trifles....


Sorry for the awful pun - I just couldn't help myself.

James
 
P

Phil Carmody

CBFalconer said:
I have this peculiar (to you, apparently) habit of searching for
food in grocery stores or restaurants, rather than hardware stores,
bicycle factories, etc. Similarly I do not search for C++
information on c.l.c. Most of the users here have the capability
of extending questions and answers in such a manner as to be
topical. If you try that, you might find that things make more
sense. You will certainly reduce the amount of useless drivel you
generate.

Inappropriate analogy.

A better one is:

You're in a vegan healthfood store (that's c.l.c), and you ask
"Do the vegeburgers contain as much protein for my growing kid
as the local butcher's freshly ground beefburgers?".
(i.e. does this language construct in your language offer the
equivalent functionality for my software project to a different
construct in another language?)

The answer "Beefburgers do not exist" is simply not helpful,
and wrong.

If I had gone into the vegan healthfood store and asked "How
long should I grill beefburgers?", then your answer would have
been appropriate. That was, however, not the case.

Phil
 
J

James Kuyper

Malcolm said:
In C++ a "Vector" is a gift-wrapped array. Specifically it flags an
error if you try to access it beyond array bounds,

It permits checked access using the at() member function. It also allows
unchecked access through the overloaded [] operator. In my very limited
amount of C++ experience, I've seen a lot more use of [] than of at().
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top