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

后端 未结 8 869
长情又很酷
长情又很酷 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:48

    Empirically, functions such as GNU getopt() permute the argument list without causing problems. As @Tim says, as long as you play sensibly, you can manipulate the array of pointers, and even individual strings. Just don't overrun any of the implicit array boundaries.

    0 讨论(0)
  • 2020-11-29 09:51

    Some libraries do this!

    The initialization method provided by the glut opengl library (GlutInit) scans for glut related arguments, and clears them by moving the subsequent elements in argv forward (moving the pointers, not the actual strings) and decrementing argc

    2.1

    glutInit glutInit is used to initialize the GLUT library.

    Usage

    void glutInit(int *argcp, char **argv);

    argcp

    A pointer to the program's unmodified argc variable from main. Upon return, the value pointed to by argcp will be updated, because glutInit extracts any command line options intended for the GLUT library.

    argv

    The program's unmodified argv variable from main. Like argcp, the data for argv will be updated because glutInit extracts any command line options understood by the GLUT library.

    0 讨论(0)
提交回复
热议问题