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

Dependencies:   Array_Matrix mbed

Revision:
0:bb939e0bc6e2
Child:
1:bbb9f0c3e523
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/InitializeStruct.hpp	Sun Oct 15 11:41:48 2017 +0000
@@ -0,0 +1,18 @@
+// 構造体の初期化
+
+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\nx1.a1 = %d, x1.a2 = %d\r\n", x1.a1, x1.a2);
+    printf("\r\nx2.a1 = %d, x2.a2 = %d\r\n", x2.a1, x2.a2);
+    printf("\r\nx3.a1 = %d, x3.a2 = %d\r\n", x3.a1, x3.a2);
+    printf("\r\nx4.a1 = %d, x4.a2 = %d\r\n", x4.a1, x4.a2);
+}