struct proc_time /* info and times about a single process*/
{
pid_t pid; /* pid of the process*/
char name[16]; /* file name of the program executed*/
unsigned long start_time; /* start time of the process*/
unsigned long real_time; /* real time of the process execution*/
unsigned long user_time; /* user time of the process*/
unsigned long sys_time; /* system time of the process*/
};
struct proctimes /* info and times about all processes we need*/
{
struct proc_time proc; /* process with given pid or current process */
struct proc_time parent_proc; /* parent process*/
struct proc_time oldest_child_proc; /* oldest child process*/
struct proc_time oldest_sibling_proc; /* oldest sibling process*/
};
我无法理解我的声明出了什么问题,我在第二个 struct
开始的行中遇到以下错误:
expected';',identifier或'('before'struct'“ .
3 回答
问题是你使用/.../作为注释分隔符是非法的 . 这条线:
应该替换为:
如果您在文件范围内声明这些结构(假设您修复了注释问题),则没有真正的原因会发生这种情况 .
但是,如果您以某种方式设法在更大的结构中声明这些结构,那么您确实会从C编译器中获得错误
在C语言中,以“嵌套”方式声明结构类型而不立即声明该类型的数据字段是非法的 .
在分号之前和结束大括号之后添加结构别名允许我编译结构(在添加main方法并包括stdlib.h之后使用gcc) .