2016-07-07 98 views
0

我試圖從MATLAB得到了一些數據進行解碼,我需要一個結構是這樣的:如何僅使用結構中的幾個結構成員在c中創建新的結構結構?

struct __attribute__((__packed__)) struct1{ 
    int a; 
    int b; 
    int c; 
} 

struct __attribute__((__packed__)) struct2{ 
    int a 
} 

struct __attribute__((__packed__)) mystruct{ 
    int struct1.a; 
    int struct1.b; 
    int struct2.a; 
    int struct1.c; 
} 

是什麼讓這個包裝的結構,這樣我可以解碼從MATLAB數據的最佳方式?如果沒有struct1和struct2的對象,我不認爲C會讓我創建mystruct。

+0

這並不清楚你在問什麼。 –

+0

最簡單的方法(對於您的具體示例而言可能最好)是成員智能副本。如果有足夠大的重疊子結構,你可以定義子結構並將它們複製到一個單獨的任務中 - 最有可能不會更快或更方便。 – tofro

回答

0

您打算使用的結構不必定義其他結構。只需用你需要的類型定義你需要的區域:

struct __attribute__((__packed__)) mystruct{ 
    int struct1_a; 
    int struct1_b; 
    int struct2_a; 
    int struct1_c; 
}