【问题标题】:Still the "error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token"仍然是“错误:在'*'标记之前的预期'=',',',';','asm'或'__attribute__'”
【发布时间】:2012-07-22 06:06:34
【问题描述】:

这是一个说明问题的小型纯 C 程序。该程序不做任何事情;它是一个大型程序的精简版,也存在同样的问题。

这是场景:

Mac OS X 狮子;

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)

那么,我错过了什么?

【问题讨论】:

  • 看起来huge 没有被识别为任何东西(我不知道它来自哪里)。也许你忘记了一个标题,可能是同一个包含 farmalloc 的标题?
  • hugebytes.com/topic/c/answers/… 上找到了一些东西。看起来它的弃用程度与far 一样严重。我只能假设farmalloc 是不必要的。如果是这种情况,杀死huges 并使用正常的malloc 应该会很好。
  • @chris:您应该将此作为答案发布(在我这样做之前!)。
  • @KeithThompson,如果你有什么要补充的,请做。我从来没有听说过,并且搜索 huge in C 来获得那个特定的并不会产生很多结果,即使有几个重点更好的关键字。
  • @chris:你已经尽我所能。

标签: c macos gcc


【解决方案1】:

我不确定huge 是什么/在哪里,但编译器无法在您提供的内容中找到它(即您可能缺少标题)。至于farmalloc,看起来在&lt;alloc.h&gt;。现在关于使用这些,another site 上有huge 的答案:

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 就足够了;没有奇怪的旧标题。

【讨论】:

  • 这听起来像是旧的 16 位 DOS 代码被移植到新环境中。
  • 是的,这是移植的“ole DOS 代码”。让我试验一下所有这些好主意。
猜你喜欢
  • 1970-01-01
  • 2016-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多