在'*'令牌之前仍然是“错误:预期'=',',',';','asm'或'__attribute__'

时间:2012-07-23 23:41:31

标签: c macos gcc

这是一个说明问题的小型纯C程序。该计划没有做任何事情;它是一个较大程序的简化版本,表现出同样的问题。

以下是该方案:

Mac OS X Lion;

gcc版本i686-apple-darwin11-llvm-gcc-4.2(GCC)4.2.1(基于Apple Inc. build 5658)(LLVM build 2335.15.00);

示例代码:

#include <stdlib.h>
#include <stdio.h>

char huge *pbA;
char huge *pbB;

int main(int argc,char *argv[])
{
    pbA = (char huge *)farmalloc(2);
    pbB = pbA;
    *(pbB++) = 'A';
    return( 0 );
}

编译命令:

gcc -c -Wall -O -g -pipe  -D_SDL myTest.c

错误讯息:

myTest.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
myTest.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
myTest.c: In function ‘main’:
myTest.c:10: error: ‘pbA’ undeclared (first use in this function)
myTest.c:10: error: (Each undeclared identifier is reported only once
myTest.c:10: error: for each function it appears in.)
myTest.c:10: error: expected ‘)’ before ‘huge’
myTest.c:10: warning: implicit declaration of function ‘farmalloc’
myTest.c:11: error: ‘pbB’ undeclared (first use in this function)

那么,我错过了什么?

1 个答案:

答案 0 :(得分:3)

我不确定huge是什么/哪里,但是编译器无法在你给出的内容中找到它(即你可能错过了一个标题)。至于farmalloc,它看起来像<alloc.h>。现在关于使用这些,huge的{​​{3}}有一个答案:

Keywords like near/far/huge were once used as memory models in the old MSDOS 
days when computers had a max of 640K memory.

Any machine built in the last 15 years does not have that restriction so 
unless you have a real issue where you have to use really obsolete hardware, 
I would not spend time with segmented memory model syntax.

huge,也可能是farmalloc,似乎被今天的标准所弃用(就像远与近指针一样)。仅使用char *malloc应该是您所需要的;没有奇怪的旧标题。