On Fri, Oct 25, 2002 at 06:23:41AM +0900, William Djaja Tjokroaminata wrote:
> Paul Brannan <pbrannan / atdesk.com> wrote:
> > I can't use a vector of strings (*), because I need to pass this data to
> > function that someone else wrote with a signature that looks like:
> >   void foo(int & argc, char ** argv);
> 
> I guess then it is that person who mixes C++ with C.  It is not even
> 
>     void foo (int argc, ...)
> 
> nor
> 
>     void foo (const int & argc, ...)

The function is designed to take argc and argv from main() and to remove
from argv the arguments that the rest of the program does not need to
see.

> This whole function argument passing is rather frightening because, first
> as pointed above, the person may modify argc, and second, then he may also
> modify argv, in which case then the original vector may be broken.  Unless
> I can read the whole content of foo, I personally will not be comfortable
> of using foo using this scheme.

The fact that argc and argv can be modified is by design.

And you are right; the original vector is not valid, unless I do:

  args.erase(args.begin() + argc, args.end());

which the program includes but I left out from my post.

> > The performance constraints the C++ standard puts on a vector almost
> > 100% guarantees this to work portably.
> 
> Because of the O(1) requirement, do you know of any instance where the
> vector is implemented differently (using a deque, perhaps)?  I do not know
> too many STL libraries.

I don't know anywhere that it is implemented differently.  Perhaps there
is a language lawyer out there who has done it just to make a point.

Paul