找不到我的语法错误,VC ++说有一个 [英] Can't find my syntax error, VC++ says there's one

查看:79
本文介绍了找不到我的语法错误,VC ++说有一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了一个问题,我在弄乱机器代码和函数指针,并且我的代码中有一些VC ++只是拒绝编译.

I'm running into a bit of a problem here, I'm messing around with machine code and function pointers, and there's a bit of my code that VC++ simply refuses to compile.

这将完全按预期进行编译和运行:

This compiles and runs exactly as expected:

#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 将不会编译以下内容,并出现此错误:error C2143: syntax error : missing ';' before 'type'

However, Visual C++ Express will not compile the following, giving this error: 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();
}

我查看了可能是错误的代码,但看不到任何错误.这是怎么回事?有什么我想念的吗?

I've looked at the supposedly faulty code and I cannot see anything wrong with it. What's going on? Is there something I'm missing?

推荐答案

这是C代码吗?如果是这样,并且不是C99,则需要在分配给tarr [X]之前将testfd的声明移至.

Is this C code? If so, and it is not C99 then you need to move the declaration of testfd to before the assignments to tarr[X].

这篇关于找不到我的语法错误,VC ++说有一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆