gpt4 book ai didi

c - 仍然是 "error: expected ‘=’、 ‘,’、 ‘;’、 ‘asm’ 或 ‘__attribute__’ token 之前的 ‘*’”

转载 作者:太空宇宙 更新时间:2023-11-04 07:33:04 28 4
gpt4 key购买 nike

这是一个说明问题的小型纯 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 ,看起来在 <alloc.h> 中.现在关于使用这些,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应该是你所需要的;没有奇怪的旧 header 。

关于c - 仍然是 "error: expected ‘=’、 ‘,’、 ‘;’、 ‘asm’ 或 ‘__attribute__’ token 之前的 ‘*’”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11622115/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com