여기에 약간의 문제가 있습니다. 컴퓨터 코드와 함수 포인터를 사용하고 있습니다. VC++에서 단순히 거부하는 코드가 있습니다. 컴파일하기.내 구문 오류를 찾을 수 없습니다. VC++에서 하나라고 말합니다.
이 컴파일 예상대로 정확히 실행: 내가 검토 한 error C2143: syntax error : missing ';' before 'type'
#include <stdlib.h>
#include <stdio.h>
int main()
{
char* tarr = (char*) malloc(1000);
tarr[0] = 0xb8;
tarr[1] = 222;
tarr[2] = 0;
tarr[3] = 0;
tarr[4] = 0;
tarr[5] = 0xc3;
int (*testfn)() = tarr; // syntax error here
printf("%d", testfn());
getchar();
}
:이 오류를주고,
#include <stdlib.h>
#include <stdio.h>
int main()
{
char tarr[] = {0xb8, 222, 0, 0, 0, 0xc3};
int (*testfn)() = tarr;
printf("%d", testfn()); // prints 222
getchar();
}
을 그러나 Visual C++ Express를 를 다음과 컴파일되지 것 코드가 잘못된 것 같아서 잘못된 점이 아무것도 없습니다. 무슨 일이야? 내가 빠진 것이 있습니까?
Visual Studio 2008에서 첫 번째 버전은 컴파일되지 않습니다. 오류 C2440 : '초기화': 'char [6]'에서 'int (__cdecl *) (void)'로 변환 할 수 없습니다. – sergiom
@sergiom VC++ 2008 Express에서 snippet이 잘 컴파일됩니다. –