首页 > 解决方案 > Xcode 警告我“malloc”的隐式声明,但 stdlib.h 包含在标头中

问题描述

我正在尝试在 Xcode 中的 C 中创建堆栈数据类型,因此使用堆栈初始化函数。

以下是在 DeckStack.c 中找到的

#define DS DeckStack

#include "DeckStack.h"


struct _DeckStack {
    void *top;
    void *cards[40];
};


DeckStack* stack_init(void) {
    DS *new_deckStack = NULL;

    new_deckStack = (DS*) malloc(sizeof(DS));
    
    return new_deckStack;
}

但是 Xcode 抱怨 malloc 的隐式声明,但 stdlib.h 包含在 DeckStack.h 中:

#ifndef DeckStack_h
#define DeckStack_h

#include <stdio.h>
#include <stdlib.h>

typedef struct _DeckStack DeckStack;


/* @brief
 
* Creates a new deck
 
*/
DeckStack* stack_init(void);

#endif /* DeckStack_h */

标签: xcode

解决方案


已解决,只需按几次 Enter,.c 文件就会使用标题的内容进行自我更新。


推荐阅读