const構造体の初期化中に、以下のQAC警告が表示されます。
"[C] Initializer for 'struct', 'union' or array type, or any object with static storage duration, must be a constant "
const PROFI_tstBlock FPARM_astFblBlockTable[] = {FPARM_ast_FblBlock_Table};
const PROFI_tstPartition FPARM_astFblPartitionTable[] = {FPARM_ast_FblPartition_Table};
上記の宣言により、QAC警告が発生します。
#define FPARM_ast_FblBlock_Table \
0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00020000 , 0x00000000 , 0x00001000 , 0x00000000 , FPARM_nMemTypeIntFlash1 , 0x01 , 0x0000 , FPARM_bi8DataBlock | FPARM_bi8CommonBlock , 0x0000
#define FPARM_ast_FblPartition_Table \
(uint32)__ghsbegin_FLoaderIdent, (uint32)0x0, (uint32)FPARM_astFblBlockTable, (uint32) 0x0, 1, 0, 0x00, 0x00, 0x00, 0x00
typedef struct PROFI_tstPartition
{
uint32 xAddressID;
uint32 u32Reserved1;
uint32 xBlockTableAdr;
uint32 u32Reserved2;
uint16 u16NumberOfBlocks;
uint16 u16GlobalProperties;
uint8 au8Reserved[4];
} PROFI_tstPartition;
typedef struct PROFI_tstBlock
{
uint32 xPhysicalAddress;
uint32 u32Reserved1;
uint32 xLogicalAddress;
uint32 u32Reserved2;
uint32 xBlockLength;
uint32 u32Reserved3;
uint32 xSectorSize;
uint32 u32Reserved4;
uint8 u8BlockMemoryType;
uint8 u8Security;
uint16 u16Reserved;
uint16 u16BlockProperties;
uint16 u16Reserved2;
} PROFI_tstBlock;
警告を回避するためにconst構造を初期化するための型キャストまたはより良い方法はありますか?
静的ストレージ期間を持つ変数は、別の変数から初期化できません。したがって、配列の場合、初期化子リスト内の他の変数への参照を含めることはできません。
このようなことをしないでください:
const type1 array1 [] = {1, 2, 3};
const type2 array2 [] = {0, array1, 0}; // won't work
代わりに、次のようなことを行います。
#define ARRAY1_INIT { 1, 2, 3 }
const type1 array1 [] = ARRAY1_INIT;
const type2 array2 [] = {0, ARRAY1_INIT, 0};
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加