Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
函数-C中存在冲突类型错误_C - Fatal编程技术网

函数-C中存在冲突类型错误

函数-C中存在冲突类型错误,c,C,我在获取一个函数时遇到了一些问题,该函数用于查找程序中运行的最重要的数字位。下面是我用来测试它的代码: #include <stdio.h> void msbFinder(unsigned int); int main() { unsigned int x; printf("Input hexadecimal: "); scanf("%x", x); unsigned int y; y = msbFinder(x); printf(

我在获取一个函数时遇到了一些问题,该函数用于查找程序中运行的最重要的数字位。下面是我用来测试它的代码:

#include <stdio.h>

void msbFinder(unsigned int);

int main()
{
    unsigned int x;
    printf("Input hexadecimal: ");
    scanf("%x", x);
    unsigned int y;
    y = msbFinder(x);
    printf("Most significant bit: %x", y);
}

unsigned int msbFinder(unsigned int x) //--Finds most significant bit in unsigned integer
{
    unsigned int a; //--Declare int that will be manipulated
    a = x; //--Initialise equal to passed value
    a = a|a>>1;
    a = a|a>>2;
    a = a|a>>4;//--var is manipulated using shifts and &'s so every value at and beneath the MSB is set to 1
    a = a|a>>8;//--This function assumes we are using a 32 bit number for this manipulation
    a = a|a>>16;
    a = a & ((~a >> 1)^0x80000000);//--Invert the int, shift it right once, & it with the uninverted/unshifted value
    return (a);//--This leaves us with a mask that only has the MSB of our original passed value set to 1
}
以及:


我已经在网上查找了解决方案,但我看不到导致此函数调用失败的故障。我需要如何修改语法才能使此函数正常工作?

在转发声明中,函数类型为
void
-

void msbFinder(unsigned int);
在定义功能时,定义为——

unsigned int msbFinder(unsigned int x)   /*  <-- type given as unsigned int  */

unsigned int msbFinder(unsigned int x)/*在正向声明中,函数类型为
void
-

void msbFinder(unsigned int);
在定义功能时,定义为——

unsigned int msbFinder(unsigned int x)   /*  <-- type given as unsigned int  */

unsigned int msbFinder(unsigned int x)/*文件顶部的声明显示:

void msbFinder(unsigned int);
函数定义说明:

unsigned int msbFinder(unsigned int x)

你看到
void
unsigned int
之间的区别了吗?声明需要与定义匹配。

文件顶部的声明显示:

void msbFinder(unsigned int);
函数定义说明:

unsigned int msbFinder(unsigned int x)

你看到
void
unsigned int
之间的区别了吗?声明需要符合定义。

该死,我是个白痴。非常感谢你…该死,我是个白痴。非常感谢你。。。