execvp second argument question - Unix

This is a discussion on execvp second argument question - Unix ; Hi, If I have a an array of string (**char args), but the size of the array is, lets say, 10, whilst the arguments are 2. If I set the third index (index no 2) to '\0', will this work ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: execvp second argument question

  1. execvp second argument question

    Hi,

    If I have a an array of string (**char args), but the size of the
    array is, lets say, 10, whilst the arguments are 2. If I set the third
    index (index no 2) to '\0', will this work for the following?

    In other words, the size of the array is larger than the number of
    elements in the array (and I set the last element to '\0')

    int rval;
    rval = execvp(myCommand, args);

    Thanks,

    Alij


  2. Re: execvp second argument question

    In article <1180745944.379655.266300@q66g2000hsg.googlegroups. com>,
    alij wrote:

    > Hi,
    >
    > If I have a an array of string (**char args), but the size of the
    > array is, lets say, 10, whilst the arguments are 2. If I set the third
    > index (index no 2) to '\0', will this work for the following?
    >
    > In other words, the size of the array is larger than the number of
    > elements in the array (and I set the last element to '\0')
    >
    > int rval;
    > rval = execvp(myCommand, args);


    There's no way in C to tell how large an array actually is. That's WHY
    execvp() requires you to set the last one to 0 -- it simply processes
    everything up to there and stops. If there's other stuff in the array
    beyond, it will be ignored.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  3. Re: execvp second argument question

    On Sat, 02 Jun 2007 18:27:39 -0400 Barry Margolin wrote:
    | In article <1180745944.379655.266300@q66g2000hsg.googlegroups. com>,
    | alij wrote:
    |
    |> Hi,
    |>
    |> If I have a an array of string (**char args), but the size of the
    |> array is, lets say, 10, whilst the arguments are 2. If I set the third
    |> index (index no 2) to '\0', will this work for the following?
    |>
    |> In other words, the size of the array is larger than the number of
    |> elements in the array (and I set the last element to '\0')
    |>
    |> int rval;
    |> rval = execvp(myCommand, args);
    |
    | There's no way in C to tell how large an array actually is. That's WHY
    | execvp() requires you to set the last one to 0 -- it simply processes
    | everything up to there and stops. If there's other stuff in the array
    | beyond, it will be ignored.

    Anything that has dynamic size or length to it has to have some means for
    that size or length to be repreented. Programmers of languages higher than
    C or C++ may never see anything that literally has the length or an ending
    point. But it is there, somewhere, in some form. It is very convenient in
    those languages to not have to deal with the actual implementation of how
    the length is known. But when programming in C, assembly, etc, for the
    most part the programmer is working at the level where they have to deal
    with how that is done. Anyone who doesn't like having to stick nuls at
    the end of a string, or put lengths at the front of the string, or keep
    a length value or end pointer in some struct, needs to find a language
    other than C (I might suggest Pike or Python).

    --
    |---------------------------------------/----------------------------------|
    | Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
    | first name lower case at ipal.net / spamtrap-2007-06-02-1733@ipal.net |
    |------------------------------------/-------------------------------------|

  4. Re: execvp second argument question

    phil-news-nospam@ipal.net writes:
    > |> If I have a an array of string (**char args), but the size of the
    > |> array is, lets say, 10, whilst the arguments are 2. If I set the third
    > |> index (index no 2) to '\0', will this work for the following?
    > |>
    > |> In other words, the size of the array is larger than the number of
    > |> elements in the array (and I set the last element to '\0')
    > |>
    > |> int rval;
    > |> rval = execvp(myCommand, args);
    > |
    > | There's no way in C to tell how large an array actually is. That's WHY
    > | execvp() requires you to set the last one to 0 -- it simply processes
    > | everything up to there and stops. If there's other stuff in the array
    > | beyond, it will be ignored.
    >
    > Anything that has dynamic size or length to it has to have some means for
    > that size or length to be repreented. Programmers of languages higher than
    > C or C++ may never see anything that literally has the length or an ending
    > point. But it is there, somewhere, in some form. It is very convenient in
    > those languages to not have to deal with the actual implementation of how
    > the length is known. But when programming in C, assembly, etc, for the
    > most part the programmer is working at the level where they have to deal
    > with how that is done. Anyone who doesn't like having to stick nuls at
    > the end of a string, or put lengths at the front of the string, or keep
    > a length value or end pointer in some struct, needs to find a language
    > other than C (I might suggest Pike or Python).



    For no particular reason except that I am using it since 1995 for all
    kinds of 'heavy lifting' tasks (and many smaller ones, too) and that
    it has always done well, I suggest - TIMTOWTDI - Perl.

    If you have trouble understanding your perl code after two days, that
    an issue with grotty programming style, not an inherent problem of the
    language, which in itself is pretty nice.

+ Reply to Thread