Is it possible to change argv or do I need to create an adjusted copy of it?

后端 未结 8 1003
长情又很酷
长情又很酷 2020-11-29 09:01

My application has potentially a huge number of arguments passed in and I want to avoid the memory of hit duplicating the arguments into a filtered list. I would like to fi

8条回答
  •  失恋的感觉
    2020-11-29 09:31

    The only time I would say that directly manipulating argv is a bad idea would be when an application changes its behavior depending on the contents of argv[0].

    However, changing a program's behavior depending on argv[0] is in itself a very bad idea where portability is a concern.

    Other than that, you can treat it just like you would any other array. As Jonathan said, GNU getopt() permutes the argument list non-destructively, I've seen other getopt() implementations that go as far as serializing and even hashing the arguments (useful when a program comes close to ARG_MAX).

    Just be careful with your pointer arithmetic.

提交回复
热议问题