具体的には、1 つのファイルと main.c から、ファイル間で typef 構造体を共有できませんでした。要約すると、私は次のことを持っています:
pagos.h:
typedef struct
{
uint8_t usuario[LONGITUD_USUARIO];
uint8_t importe[LONGITUD_IMPORTE];
uint8_t fecha[LONGITUD_TIMESTAMP];
bool posicion_ocupada;
}trama_tpv_t;
pagos.c:
#include "pagos.h"
trama_tpv_t trama_tpv;
trama_tpv_t trama_tpv;
trama_tpv_t array_trama_tpv[TAMCOLAPAGOS];
ここではtrama_tpvとarray_trama_tpv[TAMCOLAPAGOS]を使用しています。これは、いくつかの関数を使用してtrama_tpvで配列を埋めるためです。
main.c:
extern trama_tpv_t array_trama_tpv[TAMCOLAPAGOS];
編集済み: pagos.c で Bluetooth フレームを収集するため、配列を埋める方法を説明するのは少し複雑です。これは、nRF51 Bluetooth 開発キット用のファームウェアとしてコンパイルされたコードです。問題は、LCD-TFT ディスプレイに印刷するために独自のライブラリを使用してimporteとusuarioを印刷できるため、pagos.c で情報を取得することです。問題は、配列に格納されたデータで配列を印刷するために配列の値を取得する必要があることです。bool posicion_ocupadaを使用します。書き込み可能な配列位置を知るため。問題はコードのターゲットに関するものではありませんが、Java では objetc を作成するときに public を使用するだけで十分ですが、CI では何かが欠けている必要があるため、typedef 配列構造体を共有するにはどうすればよいでしょうか。リンクとコンパイルには Keil を使用していますが、これはうまく機能しているはずです。とにかく、私はXCODEで孤立した例をコーディングしようとしていますが、結果は同じです.bool、int ...を共有できますが、構造体の配列は共有できません:
typedef struct
{
bool posicion_ocupada;
}trama_tpv_t;
孤立した例: main.c:
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include "test.h"
int main(){
init();
change();
for (int i=0; i<9; i++) {
if(array_trama_tpv[i].posicion_ocupada)
printf("\nel array es true");
else
printf("\nel array es false");
}
printarray(); /*Used only because I though that maybe calling a function which is located into test.c it could be able to access the values I want from the array.*/
return(0);
test.c:
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include "test.h"
//#include "global.h"
trama_tpv_t trama_tpv;
trama_tpv_t array_trama_tpv[9];
void init(void){
for (int i=0; i<9; i++) {
array_trama_tpv[i].posicion_ocupada=false;
}
}
void change(void){
for (int i=0; i<9; i++) {
if (i<6) {
array_trama_tpv[i].posicion_ocupada=true;
}
else{
array_trama_tpv[i].posicion_ocupada=false;
}
}
}
void printarray(void){
for (int i=0; i<9; i++) {
if (array_trama_tpv[i].posicion_ocupada) {
printf("\nes true");
}
else
{
printf("\nes false");
}
}
}
test.h:
#ifndef __bittest__test__
#define __bittest__test__
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
typedef struct
{
bool posicion_ocupada;
}trama_tpv_t;
extern trama_tpv_t array_trama_tpv[9];
void init(void);
void change(void);
void printarray(void);
#endif /* defined(__bittest__test__) */
私が得る出力は次のとおりです。
el array es true
el array es true
el array es true
el array es true
el array es true
el array es true
el array es false
el array es false
el array es false
es true
es true
es true
es true
es true
es true
es false
es false
es false
問題は、同じ配列でなければならないのに、なぜ同じ結果が得られないのかということです。これは可能ですか?init() はすべてのブール値を false に設定する必要がありましたが、このように動作していません。
そして、私はそれを関数で使用しようとします。そのため、 array_trama_tpv[0].posicion_ocupadaがtrueに設定されているいくつかのブレークポイントの設定を確認しましたが、配列に沿って配列のすべての posicion_ocupada 値を出力すると、それらはすべて false になります。興味深いことに、int、bool などの変数を共有できますが、これでは値を共有できません。
前もって感謝します。私はここから多くの投稿をチェックして試してみました。
よろしく、
イヴァン