这是一个小的纯C程序,说明了这个问题。这个程序什么也不做;它是一个更大程序的精简版本,显示出同样的问题。
下面是场景:
Mac OS X狮子;
gcc版本i686-apple-darwin11-llvm-gcc-4.2(gcc)4.2.1(基于apple Inc.版本5658)(llvm版本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)

那么,我错过了什么?

最佳答案

我不确定huge是什么/在哪里,但编译器在您给出的内容中找不到它(即您可能缺少一个头)。至于farmalloc,它看起来在<alloc.h>中。现在关于使用这些,有一个关于another site的答案:

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,而且可能也huge,似乎被当今的标准所反对(就像远指针和近指针一样)。只使用farmallocchar *应该是你所需要的;没有奇怪的,老标题。

10-04 12:11