2012-12-21 135 views
0
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开始:错误:预期“;”,标识符或“(”“结构”

​​
+1

你能发布在此之前的代码吗? – Blender

回答

3

问题是你正在使用/.../作为注释分隔符这是违法的行:

struct proc_time proc; /process with given pid or current process/ 

应改为:

struct proc_time proc; /* process with given pid or current process */ 
+0

是的,它甚至在语法高亮显示中可见。 –

+0

或'struct proc_time proc; //用给定的pid或当前进程处理' – Trisped

+0

感谢您的答案。我的代码中包含/ * * /。在输入问题时只是忘记了它。评论没有问题。 – SpyrosR

0

有没有真正的理由,如果你在文件范围声明这些结构(假设你固定您的评论的问题)会发生这种情况。

然而,如果你总算来声明一个更大的结构中,这些结构,那么你确实会从C编译器得到一个错误

​​

在C语言中是违法的“嵌套声明结构类型“没有立即声明该类型的数据字段的时尚。

+0

或在发布的代码示例之前定义的其他内容。 –

0

在分号前和结束大括号之后添加struct aliases,允许我编译结构(在添加main方法并包含stdlib.h后使用gcc)。

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*/ 
} proc_time; 

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*/ 
} proctimes;