내 프로그램에서 숫자가 가장 중요한 비트를 찾기 위해 빌드 된 함수를 가져 오는 데 문제가 있습니다. 여기에 내가 그것을 테스트에 사용 된 코드입니다 :함수에서 충돌하는 유형 오류 - 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("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는 창조주를 사용하고, 그리고 오류는 다음과 같습니다
void value not ignored as it ought to be
y = msbFinder(x);
^
그리고 : 내가 찍은
conflicting types for 'msbFinder'
unsigned int msbFinder(unsigned int x)
^
을 온라인 솔루션 찾기,하지만이 함수 호출을 실패하게하는 결함을 볼 수 없습니다. 이 함수가 작동하도록하려면 구문을 수정해야합니까? 앞으로 선언 함수 타입에서
젠장, 난 바보 야. 고맙습니다 ... –