Search code examples
cmemset

What is the purpose of memset in C


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?


Solution

  • 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.