2016-07-07 95 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; 
}