我正在尝试编写一个给定传递的char指针的方法来更改Out1
和Out0
的原始值并给出按位比较函数。主文件测试各种值。但是,我一直收到一条错误消息,指出Out1
Out0
fsm
生成pointers from integers without a cast
,即使我投了它。任何帮助将不胜感激。这是代码。
#include <stdio.h>
#include <stdlib.h>
void fsm(char I1, char I0, char Reset, char *Out1, char *Out0){
int I1num = I1-'0';
int I0num = I0-'0';
int ResetNum = Reset - '0';
int Out1Num = *Out1 - '0';
int Out0Num = *Out0 - '0';
int Out1Final = (Out0Num & !I0num & Out1Num)|(!Out0Num & I0num)|(!Out0Num & !Out1Num)|(I0num & !Out1Num);
int Out0Final = ((!(Out1Num & I0num) & !(!Out1Num & I0) & !(Out1Num & !(I0))) & !Out0Num) | (!(!((!Out1Num)&(I1num))&!((Out1Num)&(!I0num)))&Out0Num);
Out1 = (char)(Out1Final);
Out0 = (char)(Out0Final);
}
/*
*
*/
int main(int argc, char** argv) {
char Out1 = '0';
char Out0 = '0';
char *Out1Ptr = &Out1;
char *Out0Ptr = &Out0;
fsm('0','0','0', *Out1Ptr, *Out0Ptr);
printf("After I1:0, I0:0, Reset:0, Q1:0, Q0:0. Out1 is %s and Out0 is %s .", *Out1Ptr, *Out0Ptr );
Out1 = '1';
Out0 = '0';
fsm('0','0','0', *Out1Ptr, *Out0Ptr);
printf("After I1:0, I0:0, Reset:0, Q1:1, Q0:0. Out1 is %s and Out0 is %s .", *Out1Ptr, *Out0Ptr );
Out1 = '1';
Out0 = '1';
fsm('0','0','0', *Out1Ptr, *Out0Ptr);
printf("After I1:0, I0:0, Reset:0, Q1:1, Q0:1. Out1 is %s and Out0 is %s .", *Out1Ptr, *Out0Ptr );
Out1 = '0';
Out0 = '1';
fsm('0','0','0', *Out1Ptr, *Out0Ptr);
printf("After I1:0, I0:0, Reset:0, Q1:0, Q0:1. Out1 is %s and Out0 is %s .", *Out1Ptr, *Out0Ptr );
Out1 = '0';
Out0 = '0';
*Out1Ptr = Out1;
*Out0Ptr = Out0;
fsm('1','0','0', *Out1Ptr, *Out0Ptr);
printf("After I1:1, I0:0, Reset:0, Q1:0, Q0:0. Out1 is %s and Out0 is %s .", *Out1Ptr, *Out0Ptr );
Out1 = '1';
Out0 = '0';
fsm('1','0','0', *Out1Ptr, *Out0Ptr);
printf("After I1:1, I0:0, Reset:0, Q1:1, Q0:0. Out1 is %s and Out0 is %s .", *Out1Ptr, *Out0Ptr );
Out1 = '1';
Out0 = '1';
fsm('1','0','0', *Out1Ptr, *Out0Ptr);
printf("After I1:1, I0:0, Reset:0, Q1:1, Q0:1. Out1 is %s and Out0 is %s .", *Out1Ptr, *Out0Ptr );
Out1 = '0';
Out0 = '1';
fsm('1','0','0', *Out1Ptr, *Out0Ptr);
printf("After I1:1, I0:0, Reset:0, Q1:0, Q0:1. Out1 is %s and Out0 is %s .", *Out1Ptr, *Out0Ptr );
Out1 = '0';
Out0 = '0';
*Out1Ptr = Out1;
*Out0Ptr = Out0;
fsm('0','1','0', *Out1Ptr, *Out0Ptr);
printf("After I1:0, I0:1, Reset:0, Q1:0, Q0:0. Out1 is %c and Out0 is %c .", *Out1Ptr, *Out0Ptr );
Out1 = '1';
Out0 = '0';
fsm('0','1','0', *Out1Ptr, *Out0Ptr);
printf("After I1:0, I0:1, Reset:0, Q1:1, Q0:0. Out1 is %c and Out0 is %c .", *Out1Ptr, *Out0Ptr );
Out1 = '1';
Out0 = '1';
fsm('0','1','0', *Out1Ptr, *Out0Ptr);
printf("After I1:0, I0:1, Reset:0, Q1:1, Q0:1. Out1 is %c and Out0 is %c .", *Out1Ptr, *Out0Ptr );
Out1 = '0';
Out0 = '1';
fsm('0','1','0', *Out1Ptr, *Out0Ptr);
printf("After I1:0, I0:1, Reset:0, Q1:0, Q0:1. Out1 is %c and Out0 is %c .", *Out1Ptr, *Out0Ptr );
Out1 = '0';
Out0 = '0';
*Out1Ptr = Out1;
*Out0Ptr = Out0;
fsm('1','1','0', *Out1Ptr, *Out0Ptr);
printf("After I1:1, I0:1, Reset:0, Q1:0, Q0:0. Out1 is %c and Out0 is %c .", *Out1Ptr, *Out0Ptr );
Out1 = '1';
Out0 = '0';
fsm('1','1','0', *Out1Ptr, *Out0Ptr);
printf("After I1:1, I0:1, Reset:0, Q1:1, Q0:0. Out1 is %c and Out0 is %c .", *Out1Ptr, *Out0Ptr );
Out1 = '1';
Out0 = '1';
fsm('1','1','0', *Out1Ptr, *Out0Ptr);
printf("After I1:1, I0:1, Reset:0, Q1:1, Q0:1. Out1 is %c and Out0 is %c .", *Out1Ptr, *Out0Ptr );
Out1 = '0';
Out0 = '1';
fsm('1','1','0', *Out1Ptr, *Out0Ptr);
printf("After I1:1, I0:1, Reset:0, Q1:0, Q0:1. Out1 is %c and Out0 is %c .", *Out1Ptr, *Out0Ptr );
return (EXIT_SUCCESS);
}
答案 0 :(得分:1)
即使我投了它。
在哪儿?我没有看到它。我所看到的只是
char *out1Ptr;
char *out0Ptr;
然后
fsm(..., ..., ..., *out1Ptr, *out0Ptr);
这不是一个类型。由于out1Ptr
和out0Ptr
的类型为char *
,因此取消引用它们会生成类型为char
的表达式,这是一个整数类型,而fsm()
则需要指针为最后两个论点。
所以编译器是对的。