【发布时间】:2020-03-08 15:40:21
【问题描述】:
我有结构 t_REC_instance,我想创建一个实例并为其变量分配内存。 我做错了什么。在注释空间中,它在调试时会给出 sigINT 错误。有人能指出我在做什么错吗。c
typedef struct sAppRecipe
{
union
{
struct sAppBread
{
int sugar_qty;
int salt_qty;
}tAppBread;
struct sAppPancake
{
int sugar_qty1;
}tAppPancake;
};
}tAppRecipe;
typedef struct sAppRecipe tAppRecipe;
struct sREC_instance
{
tAppRecipe *currentRecipe;
tAppRecipe *newRecipe;
tAppRecipe *updateRecipe;
};
typedef struct sREC_instance t_REC_instance;
tAppRecipe *REC_Alloc(void) {
return malloc(sizeof (tAppRecipe));
}
t_REC_instance *instance; //
int REC_createInstance1(t_REC_instance *instance)
{
instance->currentRecipe =REC_Alloc(); // there is a problem here
if (!instance->currentRecipe)
{
printf("not allocated");
}
}
void main()
{
REC_createInstance1(instance);
}
【问题讨论】:
标签: c pointers structure procedural-programming