2

这是 GCC 产生的奇怪错误的代码,而不是 MSVC 产生的错误(5 个错误,在错误行的注释形式中引用):

/* Match STRING against the filename pattern PATTERN, returning zero if
   it matches, nonzero if not.  */
int GNU_fnmatch (const char* pattern,const char* string,int flags)
{
    register const char *p = pattern, *n = string;
    register unsigned char c;

    #define FNM_CASEFOLD 16
    #define FNM_LEADING_DIR 8

    #define FOLD(c) ((flags & FNM_CASEFOLD) ? tolower (c) : (c))

    while ((c = *p++) != '\0')
    {
        c = FOLD (c);

        switch (c)
        {
        case '?':
            if (*n == '\0')
                return 1;
            else if ((flags & FNM_PATHNAME) && *n == '/')
                return 1;
            else if ((flags & FNM_PERIOD) && *n == '.' &&
                (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
                return 1;
            break;

        case '\\':
            if (!(flags & FNM_NOESCAPE))
            {
                c = *p++;
                c = FOLD (c);
            }
            if (FOLD ((unsigned char)*n) != c)
                return 1;
            break;

        case '*':
            if ((flags & FNM_PERIOD) && *n == '.' &&
                (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
                return 1;

            for (c = *p++; c == '?' || c == '*'; c = *p++, ++n)
            if (((flags & FNM_PATHNAME) && *n == '/') ||
            (c == '?' && *n == '\0'))
                return 1;

            if (c == '\0')
                return 0;

            {
            unsigned char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
            c1 = FOLD (c1);
            for (--p; *n != '\0'; ++n)
                if ((c == '[' || FOLD ((unsigned char)*n) == c1) &&
                GNU_fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
                return 0;
            return 1;
            }

        case '[':
            {
            /* Nonzero if the sense of the character class is inverted.  */
            register int not; // Error  1   error : expected unqualified-id before '!' token

            if (*n == '\0')
                return 1;

            if ((flags & FNM_PERIOD) && *n == '.' &&
            (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
                return 1;

            not = (*p == '!' || *p == '^'); // Error    2   error : expected primary-expression before '=' token
            if (not) // Error   3   error : expected primary-expression before ')' token
                ++p;

            c = *p++;
            for (;;)
                {
            register unsigned char cstart = c, cend = c;

            if (!(flags & FNM_NOESCAPE) && c == '\\')
                cstart = cend = *p++;

            cstart = cend = FOLD (cstart);

            if (c == '\0')
                /* [ (unterminated) loses.  */
                return 1;

            c = *p++;
            c = FOLD (c);

            if ((flags & FNM_PATHNAME) && c == '/')
                /* [/] can never match.  */
                return 1;

            if (c == '-' && *p != ']')
                {
                cend = *p++;
                if (!(flags & FNM_NOESCAPE) && cend == '\\')
                    cend = *p++;
                if (cend == '\0')
                    return 1;
                cend = FOLD (cend);

                c = *p++;
                }

            if (FOLD ((unsigned char)*n) >= cstart
                && FOLD ((unsigned char)*n) <= cend)
                goto matched;

            if (c == ']')
                break;
                }
            if (!not) // Error  4   error : expected primary-expression before ')' token
                return 1;
            break;

            matched:;
            /* Skip the rest of the [...] that already matched.  */
            while (c != ']')
                {
            if (c == '\0')
                /* [... (unterminated) loses.  */
                return 1;

            c = *p++;
            if (!(flags & FNM_NOESCAPE) && c == '\\')
                /* XXX 1003.2d11 is unclear if this is right.  */
                ++p;
                }
            if (not) // Error   5   error : expected primary-expression before ')' token
                return 1;
            }
            break;

        default:
            if (c != FOLD ((unsigned char)*n))
            return 1;
        }

        ++n;
    }

    if (*n == '\0')
        return 0;

    if ((flags & FNM_LEADING_DIR) && *n == '/')
    /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz".  */
        return 0;

    return 1;
}

我的意思是,它甚至没有意义,纠缠于一个不存在的'!' 令牌(错误 1)!!!

4

1 回答 1

6

not是 C++ 下的保留字,但在 C 下不是。

该错误是不言自明的:

if (!not) // Error  4   error : expected primary-expression before ')' token
        ^ //expecting operand for 'not' to act on, got ')' instead.

使用 GCC中的任何C 选项进行编译,或更改名称。

于 2013-01-31T11:31:35.760 回答