struct.h
Код: Выделить всё
#include
#include
#include
#include
#ifdef __cplusplus
extern "C"
{
#endif
struct my_struct_2
{
int a;
int b[5] ;
};
struct my_struct_1
{
int id;
void* arg;
struct my_struct_2 struct2;
};
struct my_struct_1 *create_struct_1();
#ifdef __cplusplus
}
#endif
Код: Выделить всё
#include "struct.h"
struct my_struct_1 *create_struct_1(){
struct my_struct_1 *t;
t= (struct my_struct_1 *) malloc(sizeof(struct my_struct_1));
assert(t!=NULL);
*t =(struct my_struct_1 ) {.id = 0, .arg = NULL, .struct2= {.a=0, .b={0}}};
return t;
}
structcpp.cpp
Код: Выделить всё
#include
#include
#include "struct.h"
int main(void)
{
struct my_struct_1* t=create_struct_1();
std::coutid
Подробнее здесь: [url]https://stackoverflow.com/questions/79361692/c-initialization-structure-linked-to-cpp-and-gcc-higher-than-13[/url]
Мобильная версия