|
下記[test.c]が下記[コンパイル結果]のように失敗します。
あれこれ試していると、変数a,b,cをstaticに変更するとコンパイルできることがわかりました。
しかし、auto変数だと失敗する理由がわかりません。
hairetuがstaticならばa,b,cもstaticでないといけないでしょうが、
hairetuがautoなんだからa,b,cもautoでいいように思います。
[test.c]
/*
* No.29658 関数(データの引渡し)投稿者---kasai(2007/01/31 08:50:53)
* http://www2.realint.com/cgi-bin/tarticles.cgi?pointc+29658
*/
#include <stdio.h>
void smp(int **hairetu);
int main(void)
{
int a=10;
int b=20;
int c=30;
int *hairetu[] = {&a, &b, &c};
smp(hairetu);
printf("%d %d %d", a, b, c);
return 0;
}
void smp(int **hairetu)
{
int i;
hairetu++ ;
for(i=1;i<3;i++,hairetu++){
**hairetu *= 10;
**hairetu += **(hairetu-1);
}
}
[コンパイル結果] 環境:Win2000, LSI C-86 Compiler ver 3.30c, Borland C++ 5.5 for Win32
>lcc test.c
test.c 9: non-constant expression
test.c 9: non-constant expression
test.c 9: non-constant expression
>bcc32 test.c
Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland
test.c:
エラー E2063 test.c 14: 不正な初期化(関数 main )
*** 1 errors in Compile ***
>
|