【问题标题】:C: struct declaration with function. Storage size isn't knownC:带有函数的结构声明。存储大小未知
【发布时间】:2013-05-26 16:39:11
【问题描述】:

关于在struct 中使用函数的问题。我从 R.Stevens 的书中拿了 sn-p,我看到了几次类似的 sn-ps。我建议获得一些 C 和 Linux 经验,但我真的不知道在这种情况下如何正确使用 struct。

struct stat buf; // The error line              

for (i=1; i < argc; i++){        
  if (lstat(argv[i], &buf) < 0) { // Usage of
    err_ret("lstat error");      
    continue;                    
  }                              
  if (S_ISERG(buf.st_mode))      
    ptr = "regular";             

编译代码时出现错误:

type.c: In function ‘main’:
type.c:9:15: error: storage size of ‘buf’ isn’t known

结构声明有什么问题?我应该明确声明结构大小吗?如果是,我怎么知道?主要问题 - 它是如何工作的struct method name

【问题讨论】:

  • 你有围绕其中一些声明的主程序吗?

标签: c function struct


【解决方案1】:

你忘了包括:

   #include <sys/types.h>
   #include <sys/stat.h>

【讨论】:

  • 是的,我忘了包括所有这些!我将阅读有关这些库的信息。谢谢!
  • 不客气;但从技术上讲,这些不是库,而是包含文件,描述了标准 C 库中的*stat() 函数..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-07
  • 2013-05-19
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多