お世話になっております。
要素数が約3200個の2バイトの符号付整数の配列を、それを参照する関数の外においておきました。
関数から参照させると、「Expression must have pointer-to-object type」(式はオブジェクト型へのポインタである必要があります。)というコンパイルエラーとなってしまいました。
関数の外(別のソースファイル)に作成した配列は次のような記述です。 (抜粋)
static const int16_t thermistor_10K[3211] = { -400,-400,-399,-398,-398,-397,-396,-396,-395,-394, -394,-393,-392,-392,-391,-390,-390,-389,-389,-388,
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
689,690,690,691,691,692,692,693,693,694, 695,695,696,696,697,697,698,698,699,699, 700};
関数の、配列を参照している箇所の記述は、次の通りです。
extern int16_t thermistor_10K;
void main(){
int16_t hoge;
hoge = thermistor_10K[1750];
}
// ※ あまり詳細には書けませんので、必要な部分のみ書きました。
配列としては、普通の配列と思うのですが、サイズが大きい(約6KByte)ために、上記のようなエラーとなってしまったのでしょうか。
コンパイラの制限によるものなのか、それともそもそも定義の方法に誤りがあるのかわからず、困っております。
大変お手数をおかけしますが、ご教示何卒よろしくお願いします。
static const int16_t thermistor_10K[3211] = {
↑は
const int16_t thermistor_10K[3211] = {
↑の間違い、
extern const int16_t thermistor_10K[3211];
↑の間違いですね。
hoge.c:
#include "hoge.h" #include <stdint.h> const int16_t thermistor_10K[3211] = { -400,-400,-399,-398,-398,-397,-396,-396,-395,-394, -394,-393,-392,-392,-391,-390,-390,-389,-389,-388, ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・ ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・ 689,690,690,691,691,692,692,693,693,694, 695,695,696,696,697,697,698,698,699,699, 700 };
hoge.h:
#ifndef _HOGE_H_ #define _HOGE_H_ #include <stdint.h> extern const int16_t thermistor_10K[3211]; #endif/*_HOGE_H_*/
piyo.c:
#include "hoge.c" #include <stdint.h> void main(){ int16_t hoge; hoge = thermistor_10K[1750]; }
等とするとこの手のミスを防ぐことができます。それ以前の話としてよく分かってらっしゃらないようなので、Amazon 辺りで評判の良い C の入門書でも調べて読まれたらいかがですか。
訂正:
piyo.c の
#include "hoge.c"
は
#include "hoge.h"
の間違い