いろいろなテクニック.Nucleo と DISCO-F746 用.

Dependencies:   Array_Matrix mbed

InitializeStruct.hpp

Committer:
MikamiUitOpen
Date:
2019-04-10
Revision:
1:bbb9f0c3e523
Parent:
0:bb939e0bc6e2

File content as of revision 1:bbb9f0c3e523:

// 構造体の初期化

void InitializeStruct()
{
    struct myStruct{ int a1; int a2; };
    
    myStruct x1 = { a1: 1, a2: 2 };
    myStruct x2 = { .a1 = -3, .a2 = -4 };
    myStruct x3 = { 5, 6 };     // 初期化なので OK
    myStruct x4;
//    x4 = {-7, -8};    // エラー,代入なので使えない
    x4 = (myStruct){-7, -8};    // 複合リテラル(compound literal)を利用 
    
    printf("\r\n");
    printf("x1.a1 = %2d,  x1.a2 = %2d\r\n", x1.a1, x1.a2);
    printf("x2.a1 = %2d,  x2.a2 = %2d\r\n", x2.a1, x2.a2);
    printf("x3.a1 = %2d,  x3.a2 = %2d\r\n", x3.a1, x3.a2);
    printf("x4.a1 = %2d,  x4.a2 = %2d\r\n", x4.a1, x4.a2);
}