在 C 中,我可以推迟头文件的 "typedef" 直到我包含并使用头文件吗?

In C, can I put off the "typedef" of a header file until I include and use the header file?

我有 2 个文件:stack.hstack.c。他们都有一个未定义的类型 elem_type.

所以我的问题是:我可以在包含 stack.h 之前让它们保持未定义状态,然后根据调用文件的需要给它一个定义吗?

您不能在 C 中的 stack.c 中保留未定义的类型,因为当编译器尝试编译 stack.c 时,它将无法确定类型。

在 C++ 中,这可以通过模板实现。