'的冲突类型;功能';函数的隐式声明';功能';在C99中无效

'的冲突类型;功能';函数的隐式声明';功能';在C99中无效,c,xcode,C,Xcode,关于这些问题的其他答案是在头文件中或在main()之前声明函数,但我有这两个选项,它仍然不起作用 #include <stdbool.h> #ifndef WORK #define WORK #define TRACING true #define DIMENSION 4 #define TOUR_LENGTH 15 void trace(char *s); //error here "Conflicting types for 'trace'" #endif ^所讨论的功

关于这些问题的其他答案是在头文件中或在main()之前声明函数,但我有这两个选项,它仍然不起作用

#include <stdbool.h>

#ifndef WORK
#define WORK

#define TRACING true
#define DIMENSION 4
#define TOUR_LENGTH 15

void trace(char *s); //error here "Conflicting types for 'trace'"

#endif
^所讨论的功能。该函数在所有带有#include work.h的其他.c文件中多次使用

#include <stdbool.h>
#include "work.h"
#include "gameTree.h"
#include "gameState.h"
#include "stack.h"
#include <stdio.h>


/*
    *   trace
    *   Provide trace output.
    *   Pre-condition: none
    *   Post-condition: if trace output is desired then the given String
    *                   parameter is shown on the console
    *   Informally: show the given message for tracing purposes
    *
    *   param s the String to be displayed as the trace message
*/
void trace(char *s) //error here "Conflicting types for 'trace'"
{
    if (TRACING)
    {
        printf("%s\n",s);
    }
}


/*
*   intro
*   Provide introductory output.
*   Pre-condition: none
*   Post-condition: an introduction to the progrm has been displayed
*   Informally: give the user some information about the program
*/
void intro()
{
    printf("Knight's Tour\n");
    printf("=============\n");
    printf("Welcome to the Knight's Tour.  This is played on a(n) %d x %d board.  The\n",DIMENSION,DIMENSION);
    printf("knight must move %d times without landing on the same square twice.\n",TOUR_LENGTH);
    printf("\n");
}


/*
*   main
*   Program entry point.
*   Pre-condition: none
*   Post-condition: the solution to the Knight's Tour will be found
*                   and displayed
*   Informally: solve the Knight's Tour
*/
int main(int argc, char *argv[])
    {
gameTree g,a;   // whole game tree and solution game tree
    gameState s;    // initial game state
    stack k,r;      // stack for intermediate DF use and for tracing solution
    queue q;        // queue for intermediate BF use

    // give introduction
    intro();

    // initialise data structures
    init_stack(&k);
    init_queue(&q);
    init_gameState(&s, 1, 1);   // start at top left-hand corner: (1,1)

    // show initial board
    printf("\nStarting board:\n");
    showGameState(s);
    printf("\n");

    // solve
    init_gameTree(&g, false, s, 1);
    a = buildGameDF(g, k, TOUR_LENGTH);     // Depth-first
    //a = buildGameBF(g, q, TOUR_LENGTH);   // Breadth-first

    // show results
    if (isEmptyGT(a))
    {
        printf("No solution!\n");
    }
    else
    {
        // re-trace solution from leaf to root
        init_stack(&r);
        do
        {
            push(r, a);
            a = getParent(a);
        } while (!isEmptyGT(a));

        // display move list
        while (!isEmptyS(r))
        {
            a = (gameTree)top(r);
            s = (gameState)getData(a);
            printf("Move %d: (%d,%d)\n", getLevel(a), getRow(s), getColumn(s));
            pop(r);
        }

        // display final path
        printf("\nFinal board:\n");
        showGameState(s);
    }
^调用跟踪函数的位置示例

#include <stdbool.h>
#include "tNode.h"
#include "gameTree.h"
#include "work.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
我无法确定是什么导致了某些错误,但如果它与导入不正确的头文件有关,那么它不应该一直保持一致吗


我还应该注意,这些文件是给我使用的,所以我没有编写原始跟踪函数。

从您的代码示例中不清楚
是否包含在某些源文件中。MacOS上的
中已经定义了一个函数
跟踪

/usr/include/curses.h:1710:extern NCURSES_EXPORT(void) trace (const unsigned int);
如果这是实际问题,则需要将
trace
函数重命名为其他函数

从上下文来看,您可能应该使用一个宏
TRACE(…)
,该宏扩展为对
fprintf(stderr,u VA_ARGS)
的调用,除非您为发布版本编译,在这种情况下,它将扩展为零

出现警告的另一个潜在原因是原型:

void trace(char *s);
void trace(const char *s);
char*
参数传递字符串常量可能会导致警告。由于
trace
不会修改字符串参数的内容,因此应该声明它为
const char*
。通过修改原型解决此问题:

void trace(char *s);
void trace(const char *s);

您似乎遗漏了您的
main.cpp
#include
列表和标记您声明的警告的具体用法。如果你认为它们不相关,请三思。就我们所知,函数调用puking的警告是
printf
,因为您忽略了包含
stdio.h
。所包含的任何其他文件
#是否定义了
工作
?感谢您的更新。在哪一行发出警告?在你的问题源列表中贴一条注释,注意这一行。您确信(a)包含的
work.h
文件就是您想要的文件,(b)在将
work.h
包含在某个源文件中之前未定义
work.h
,以及(c)在使用上述函数之前,使用
trace
的任何文件都包含
work.h
?检查您编写的所有.h文件,确保
WORK
未用作其他头文件的include-fencepost。错误消息是什么?同时给出完整的源代码,而不是拆分的包含和代码。在这种情况下,文件的确切内容是强制性的。
void trace(const char *s);