编译时“程序断言中的'stray'#'”错误

时间:2016-05-24 14:47:38

标签: c

我一直收到使用断言函数的代码块的上述错误消息,我不知道为什么会这样。我在互联网上搜索这个错误的潜在答案..没有成功。因此,非常感谢任何/所有的帮助。

以下是引发此错误的上述代码块:

#include <stdio.h>
#include <assert.h>

typedef struct WORD
{
    char *Word;
    size_t Count;
    struct WORD *Left;
    struct WORD *Right;
} WORD;

#define SUCCESS                      0
#define NO_MEMORY_FOR_WORDNODE       3
#define NO_MEMORY_FOR_WORD           4

int AddToTree(WORD **DestTree, size_t *Treecount, char *Word)
{
    int Status = SUCCESS;
    int CompResult = 0;

    /* safety check */
    assert(NULL != DestTree);
    assert(NULL != Treecount);
    assert(NULL != Word);

    /* DestTree is NULL or it isn't */
    if(NULL == *DestTree){ /* this is the place to add it then */
        *DestTree = malloc(sizeof **DestTree);
        if(NULL == *DestTree){
            /* out of memory */
            Status = NO_MEMORY_FOR_WORDNODE;
        }
        else {
            (*DestTree)->Left = NULL;
            (*DestTree)->Right = NULL;
            (*DestTree)->Count = 1;
            (*DestTree)->Word = dupstr(Word);
            if(NULL == (*DestTree)->Word){
                /* out of memory in the middle */
                Status = NO_MEMORY_FOR_WORD; 
                free(*DestTree);
                *DestTree = NULL;
            }
            else {
                /* everything worked, add one to the tree nodes count */
                ++*Treecount;
            }
        }
    }
    else { /* we need to make a decision */
        CompResult = strcmp(Word, (*DestTree)->Word);
        if(0 < CompResult){
            Status = AddToTree(&(*DestTree)->Left, Treecount, Word);
        }
        else if(0 > CompResult){
            Status = AddToTree(&(*DestTree)->Left, Treecount, Word);
        }
        else {
            /* add one to the count - this is the same node */
            ++(*DestTree)->Count;
        }
    }  /* end of else we need to make a decision */
    return Status;  
}

请注意,每个断言行都会抛出相同的错误。

我接受了@alk的建议来检查预处理器输出,这就是我得到的:

# 2 "ex6-4.c" 2
# 1 "c:\\mingw\\include\\assert.h" 1 3
# 38 "c:\\mingw\\include\\assert.h" 3
void __attribute__((__cdecl__)) __attribute__ ((__nothrow__)) _assert (const ch
ar*, const char*, int) __attribute__ ((__noreturn__));
# 16 "ex6-4.c" 2`

我必须承认,这对我来说和有问题的错误一样重要。

0 个答案:

没有答案