The code block is listed below

/*************** Micro getopt() *********************************************/
#define OPTION(c,v) (_O&2&&**v?*(*v)++:!c||_O&4?0:(!(_O&1)&& \
                (--c,++v),_O=4,c&&**v=='-'&&v[0][1]?*++*v=='-'\
                &&!v[0][1]?(--c,++v,0):(_O=2,*(*v)++):0))
#define OPTARG(c,v) (_O&2?**v||(++v,--c)?(_O=1,--c,*v++): \
                (_O=4,(char*)0):(char*)0)
#define OPTONLYARG(c,v) (_O&2&&**v?(_O=1,--c,*v++):(char*)0)
#define ARG(c,v)    (c?(--c,*v++):(char*)0)

static int _O = 0;      /* Internal state */
/*************** Micro getopt() *********************************************/

I know this macros are used for get the args of main function,but not fully understand it. Now the question is what's the _O mean in this block,and how it works.

有帮助吗?

解决方案

Like the comment says, it's internal state the macros use to remember where they are and what they're doing. Nothing you need to worry about unless you are reimplementing the code, in which case the complete lack of documentation apart from that comment and the general coding style suggest you might have a problem.

As it's static it is only accessible from that file (God help you if that code is from a header) and it has a lifetime the same as the executing program.

But basically, you should not touch _O in your code.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top