문제

I am reading REBOL source code and I can't understand the purpose of the following statement:

/***********************************************************************
**
*/  int main(int argc, char **argv)
/*
***********************************************************************/
{
    char *cmd;

    // Parse command line arguments. Done early. May affect REBOL boot.
    Parse_Args(argc, argv, &Main_Args);

    Print_Str("REBOL 3.0\n");

    REBOL_Init(&Main_Args);

    // Evaluate user input:
    while (TRUE) {
        cmd = Prompt_User();
        REBOL_Do_String(cmd);
        if (!IS_UNSET(DS_TOP)) {
            //if (DSP > 0) {
                if (!IS_ERROR(DS_TOP)) {
                    Prin("== ");
                    Print_Value(DS_TOP, 0, TRUE);
                } else
                    Print_Value(DS_TOP, 0, FALSE);
            //}
        }
        //DS_DROP; // result
    }

    return 0;
}

In Parse_Args function:

/***********************************************************************
**
*/  void Parse_Args(int argc, REBCHR **argv, REBARGS *rargs)
/*
**      Parse REBOL's command line arguments, setting options
**      and values in the provided args structure.
**
***********************************************************************/
{
    REBCHR *arg;
    REBCHR *args = 0; // holds trailing args
    int flag;
    int i;

    CLEARS(rargs);

    ....

And CLEARS is defined:

#define CLEARS(m)       memset((void*)(m), 0, sizeof(*m));

So my question is why memset is being used here?

도움이 되었습니까?

해결책

It looks like rargs is some kind of struct containing options for the program. CLEARS() and memset() is used to fill that struct with zero values to initiate it.

다른 팁

memset sets a block of memory to a given value. It is normally written in hand optimized assembly and is expected to be blindingly fast.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top