Is argv writeable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Malkis

    Is argv writeable?

    Supposed the ith actual argument argv[i] has length n. Am I allowed to
    write any string of length <=n to argv[i] ?

    Thanks in advance,
    Alex.

    PS. To email me, remove "loeschedie s" from the email address given.
  • Howard

    #2
    Re: Is argv writeable?


    "Alexander Malkis" <alexloeschedie smalk@face.cs.u ni-sb.de> wrote in message
    news:c8iguc$2ei eo$3@hades.rz.u ni-saarland.de...[color=blue]
    > Supposed the ith actual argument argv[i] has length n. Am I allowed to
    > write any string of length <=n to argv[i] ?
    >
    > Thanks in advance,
    > Alex.
    >
    > PS. To email me, remove "loeschedie s" from the email address given.[/color]

    If I recall, some systems do not even provide facilities for command-line
    arguments. On systems that do, I think it's implementation and
    system-specific as to how it's implemented.

    But since there is no const in those arguments, I imagine it's theoretically
    possible to write to those locations. The question is...why? They're not
    outputs. Changing them won't change what was on the command line when the
    program was invoked.

    If you want to hold onto the array and modify its content, then make your
    own copies of the strings in appropriate data structures (a vector of string
    type seems appropriate), and manipulate those. That way you're sure it will
    work (provided of course that you can get those command line arguments in
    the first place).

    -Howard



    Comment

    • Jeff Schwab

      #3
      Re: Is argv writeable?

      Howard wrote:[color=blue]
      > "Alexander Malkis" <alexloeschedie smalk@face.cs.u ni-sb.de> wrote in message
      > news:c8iguc$2ei eo$3@hades.rz.u ni-saarland.de...
      >[color=green]
      >>Supposed the ith actual argument argv[i] has length n. Am I allowed to
      >>write any string of length <=n to argv[i] ?
      >>
      >>Thanks in advance,
      >>Alex.
      >>
      >>PS. To email me, remove "loeschedie s" from the email address given.[/color]
      >
      >
      > If I recall, some systems do not even provide facilities for command-line
      > arguments. On systems that do, I think it's implementation and
      > system-specific as to how it's implemented.
      >
      > But since there is no const in those arguments, I imagine it's theoretically
      > possible to write to those locations. The question is...why? They're not
      > outputs. Changing them won't change what was on the command line when the
      > program was invoked.[/color]

      On some Unices, changing the contents of argv is a tricky way to change
      the output shown by "ps", e.g. to display the progress of a process
      instead of just its name. Of course, a more platform-specific hack
      there never was...

      Comment

      • Gianni Mariani

        #4
        Re: Is argv writeable?

        Howard wrote:[color=blue]
        > "Alexander Malkis" <alexloeschedie smalk@face.cs.u ni-sb.de> wrote in message
        > news:c8iguc$2ei eo$3@hades.rz.u ni-saarland.de...
        >[color=green]
        >>Supposed the ith actual argument argv[i] has length n. Am I allowed to
        >>write any string of length <=n to argv[i] ?
        >>
        >>Thanks in advance,
        >>Alex.
        >>
        >>PS. To email me, remove "loeschedie s" from the email address given.[/color]
        >
        >
        > If I recall, some systems do not even provide facilities for command-line
        > arguments. On systems that do, I think it's implementation and
        > system-specific as to how it's implemented.
        >
        > But since there is no const in those arguments, I imagine it's theoretically
        > possible to write to those locations. The question is...why? They're not
        > outputs. Changing them won't change what was on the command line when the
        > program was invoked.
        >
        > If you want to hold onto the array and modify its content, then make your
        > own copies of the strings in appropriate data structures (a vector of string
        > type seems appropriate), and manipulate those. That way you're sure it will
        > work (provided of course that you can get those command line arguments in
        > the first place).[/color]

        One example is this:

        void main ( int argc, char **argv )
        {

        Widget shell, msg;
        XtAppContext app;
        XmString xmstr;
        shell = XtAppInitialize (&app, "Memo", NULL, 0, &argc, argv, NULL,
        NULL, 0 );

        This is a standard way to initialize an Xt application where command
        line arguments are consumed by the library and the function
        XtAppInitialize is expected to remove the argv components it has used
        leaving the application specific components for the application to consume.

        ....

        Comment

        • Default User

          #5
          Re: Is argv writeable?

          Alexander Malkis wrote:[color=blue]
          >
          > Supposed the ith actual argument argv[i] has length n. Am I allowed to
          > write any string of length <=n to argv[i] ?[/color]


          Yes.




          Brian Rodenborn

          Comment

          • Howard

            #6
            Re: Is argv writeable?


            "Gianni Mariani" <gi2nospam@mari ani.ws> wrote in message
            news:c8ilrq$aj8 @dispatch.conce ntric.net...
            [color=blue][color=green]
            > > The question is...why?[/color][/color]
            [color=blue]
            >
            > One example is this:
            >
            > void main ( int argc, char **argv )
            > {
            >
            > Widget shell, msg;
            > XtAppContext app;
            > XmString xmstr;
            > shell = XtAppInitialize (&app, "Memo", NULL, 0, &argc, argv, NULL,
            > NULL, 0 );
            >
            > This is a standard way to initialize an Xt application where command
            > line arguments are consumed by the library and the function
            > XtAppInitialize is expected to remove the argv components it has used
            > leaving the application specific components for the application to[/color]
            consume.[color=blue]
            >[/color]

            Interesting! Looks quite useful.

            As I said, the signature sure seems to allow writing to argv. But does the
            standard guarantee it?

            -Howard






            Comment

            • Minti

              #7
              Re: Is argv writeable?

              Gianni Mariani <gi2nospam@mari ani.ws> wrote in message news:<c8ilrq$aj 8@dispatch.conc entric.net>...[color=blue]
              > Howard wrote:[color=green]
              > > "Alexander Malkis" <alexloeschedie smalk@face.cs.u ni-sb.de> wrote in message
              > > news:c8iguc$2ei eo$3@hades.rz.u ni-saarland.de...
              > >[color=darkred]
              > >>Supposed the ith actual argument argv[i] has length n. Am I allowed to
              > >>write any string of length <=n to argv[i] ?
              > >>
              > >>Thanks in advance,
              > >>Alex.
              > >>
              > >>PS. To email me, remove "loeschedie s" from the email address given.[/color]
              > >
              > >
              > > If I recall, some systems do not even provide facilities for command-line
              > > arguments. On systems that do, I think it's implementation and
              > > system-specific as to how it's implemented.
              > >
              > > But since there is no const in those arguments, I imagine it's theoretically
              > > possible to write to those locations. The question is...why? They're not
              > > outputs. Changing them won't change what was on the command line when the
              > > program was invoked.
              > >
              > > If you want to hold onto the array and modify its content, then make your
              > > own copies of the strings in appropriate data structures (a vector of string
              > > type seems appropriate), and manipulate those. That way you're sure it will
              > > work (provided of course that you can get those command line arguments in
              > > the first place).[/color]
              >
              > One example is this:
              >
              > void main ( int argc, char **argv )[/color]
              ^^^^

              void(?)

              --
              Imanpreet Singh Arora

              Comment

              • Mike Wahler

                #8
                Re: Is argv writeable?


                "Howard" <alicebt@hotmai l.com> wrote in message
                news:lV5rc.8685 $fF3.212014@bgt nsc05-news.ops.worldn et.att.net...[color=blue]
                >
                > "Gianni Mariani" <gi2nospam@mari ani.ws> wrote in message
                > news:c8ilrq$aj8 @dispatch.conce ntric.net...
                >[color=green][color=darkred]
                > > > The question is...why?[/color][/color]
                >[color=green]
                > >
                > > One example is this:
                > >
                > > void main ( int argc, char **argv )
                > > {
                > >
                > > Widget shell, msg;
                > > XtAppContext app;
                > > XmString xmstr;
                > > shell = XtAppInitialize (&app, "Memo", NULL, 0, &argc, argv, NULL,
                > > NULL, 0 );
                > >
                > > This is a standard way to initialize an Xt application where command
                > > line arguments are consumed by the library and the function
                > > XtAppInitialize is expected to remove the argv components it has used
                > > leaving the application specific components for the application to[/color]
                > consume.[color=green]
                > >[/color]
                >
                > Interesting! Looks quite useful.
                >
                > As I said, the signature sure seems to allow writing to argv. But does[/color]
                the[color=blue]
                > standard guarantee it?[/color]

                The C (99) standard does explicitly make this gurantee, but
                I don't see it in the C++(98) standard. (Or maybe I'm looking
                in the wrong place ... wouldn't be the first time. :-) )

                -Mike


                Comment

                • Default User

                  #9
                  Re: Is argv writeable?

                  Mike Wahler wrote:
                  [color=blue]
                  > The C (99) standard does explicitly make this gurantee, but
                  > I don't see it in the C++(98) standard. (Or maybe I'm looking
                  > in the wrong place ... wouldn't be the first time. :-) )[/color]

                  As did the C89 standard before it. I wonder why they left out that bit
                  of boilerplate, if it's missing from the final standard (I just have the
                  last draft).

                  The C standard says:

                  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.



                  Brian Rodenborn

                  Comment

                  • Mike Wahler

                    #10
                    Re: Is argv writeable?


                    "Default User" <first.last@boe ing.com.invalid > wrote in message
                    news:40AE6AB1.4 48AC027@boeing. com.invalid...[color=blue]
                    > Mike Wahler wrote:
                    >[color=green]
                    > > The C (99) standard does explicitly make this gurantee, but
                    > > I don't see it in the C++(98) standard. (Or maybe I'm looking
                    > > in the wrong place ... wouldn't be the first time. :-) )[/color]
                    >
                    > As did the C89 standard before it. I wonder why they left out that bit
                    > of boilerplate, if it's missing from the final standard (I just have the
                    > last draft).
                    >
                    > The C standard says:
                    >
                    > 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.[/color]

                    Yes, I found that, but no similar wording in the C++ standard.

                    -Mike


                    Comment

                    Working...