What is user gcc's purpose in requesting code possibly like this?

Posted by James Morris on Stack Overflow See other posts from Stack Overflow or by James Morris
Published on 2010-05-22T19:48:10Z Indexed on 2010/05/22 19:50 UTC
Read the original article Hit count: 189

Filed under:
|

In the question between syntax, are there any equal function the user gcc is requesting only what I can imagine to be the following code:

#include <stdio.h>
#include <string.h>


/* estimated magic values */
#define MAXFUNCS   8
#define MAXFUNCLEN 3



int the_mainp_compare_func(char** mainp)
{
    char mainp0[MAXFUNCS][MAXFUNCLEN] = { 0 };
    char mainp1[MAXFUNCS][MAXFUNCLEN] = { 0 };

    char* psrc, *pdst;

    int i = 0;
    int func = 0;

    psrc = mainp[0];

    printf("scanning mainp[0] for functions...\n");

    while(*psrc)
    {
        if (*psrc == '\0')
            break;
        else if (*psrc == ',')
            ++psrc;
        else
        {
            mainp0[func][0] = *psrc++;
            if (*psrc == ',')
            {
                mainp0[func][1] = '\0';
                psrc++;
            }
            else if (*psrc !='\0')
            {
                mainp0[func][1] = *psrc++;
                mainp0[func][2] = '\0';
            }
            printf("function: '%s'\n", mainp0[func]);
        }
        ++func;
    }

    printf("\nscanning mainp[1] for functions...\n");

    psrc = mainp[1];

    func = 0;

    while(*psrc)
    {
        if (*psrc == '\0')
            break;
        else if (*psrc == ',')
            ++psrc;
        else
        {
            mainp1[func][0] = *psrc++;
            if (*psrc == ',')
            {
                mainp1[func][1] = '\0';
                psrc++;
            }
            else if (*psrc !='\0')
            {
                mainp1[func][1] = *psrc++;
                mainp1[func][2] = '\0';
            }
            printf("function: '%s'\n", mainp1[func]);
        }
        ++func;
    }

    printf("\ncomparing functions in '%s' with those in '%s'\n",
                                    mainp[0],         mainp[1] );

    int func2;

    func = 0;

    while (*mainp0[func] != '\0')
    {
        func2 = 0;
        while(*mainp1[func2] != '\0')
        {
            printf("comparing %s with %s\n", mainp0[func], mainp1[func2]);
            if (strcmp(mainp0[func], mainp1[func2++]) == 0)
                return 1; /* not sure what to return here */
        }
        ++func;
    }

    /* no matches == failure */

    return -1; /* not sure what to return on failure */
}


int main(int argc, char** argv)
{
    char* mainp[] = { "P,-Q,Q,-R", "R,A,P,B,F" };

    if (the_mainp_compare_func(mainp) == 1)
        printf("a match was found, but I don't know what to do with it!\n");
    else
        printf("no match found, and I'm none the wiser!\n");

    return 0;
}

My question is, what is it's purpose?

© Stack Overflow or respective owner

Related posts about c

    Related posts about subjective