gpt4 book ai didi

函数中的冲突类型错误 - C

转载 作者:太空宇宙 更新时间:2023-11-04 06:19:04 25 4
gpt4 key购买 nike

<分区>

我在获取用于查找在我的程序中运行的数字最高有效位的函数时遇到问题。这是我用来测试它的代码:

#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
}

我正在使用 Qt Creator,错误是:

void value not ignored as it ought to be
y = msbFinder(x);
^

和:

conflicting types for 'msbFinder'
unsigned int msbFinder(unsigned int x)
^

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com