0

これは、問題を説明する小さな純粋な 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)

それで、私は何が欠けていますか?

4

1 に答える 1

3

何が/どこにhugeあるのかわかりませんが、コンパイラはあなたが与えたものでそれを見つけることができません (つまり、おそらくヘッダーがありません)。に関してはfarmalloc、それは にあるようです<alloc.h>これらの使用については、別のサイト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同様に、今日の標準では非推奨になっているようです(遠ポインタと近ポインタのように)。just char *andを使用するだけでmalloc十分です。奇妙で古いヘッダーはありません。

于 2012-07-24T00:03:35.037 に答える