|
|
 |
 |
 |
 |
get processs name; error: dereferencing pointer to incomplete type
line 7: error: dereferencing pointer to incomplete type 1. #include<stdio.h> 2. #include<sys/stat.h> 3. #include<stdlib.h> 4. void execname() { 5. struct task_struct *my; 6. my = find_task_by_id(getpid()); 7. printf("%s",my->comm); error: dereferencing pointer to incomplete type 8. 9. } 10. int main() 11. { 12. execname(); 13. } what's wrong with it
On Jun 7, 12:03 am, Pritam <chh@gmail.com> wrote:
> line 7: error: dereferencing pointer to incomplete type > 1. #include<stdio.h> > 2. #include<sys/stat.h> > 3. #include<stdlib.h> > 4. void execname() { > 5. struct task_struct *my; > 6. my = find_task_by_id(getpid()); > 7. printf("%s",my->comm); error: dereferencing pointer to incomplete > type > 8. > 9. } > 10. int main() > 11. { > 12. execname(); > 13. } > what's wrong with it
You haven't included whatever header(s) you need to define the structure type task_struct. This structure isn't defined by the C standard, so you need to look in the documentation for programming on whatever OS you are using, or ask in a newsgroup which discusses programming on that OS.
On Thu, 07 Jun 2007 07:03:08 -0000, Pritam <chh @gmail.com> wrote: >line 7: error: dereferencing pointer to incomplete type >1. #include<stdio.h> >2. #include<sys/stat.h> >3. #include<stdlib.h> >4. void execname() { >5. struct task_struct *my;
The standard guarantees that all pointers to struct have the same representation. Therefore, the compiler knows everything it needs to reserve the correct amount of space with the correct alignment for the object my. But at this point, the only thing the compiler knows about struct task_struct is that it is a structure. >6. my = find_task_by_id(getpid());
Presumably the function is declared in one of your non-standard headers and returns either a void* or a struct task_struct*. If this is the case, the compiler has enough information to generate the correct code for this statement. If it is not the case, you have omitted at least one mandatory diagnostic. >7. printf("%s",my->comm); error: dereferencing pointer to incomplete >type
However, at this point, the compiler needs to know the internal structure of the object pointed to by my. Is there a member named comm? Is it a char*? Where in the structure is it located? You have failed to provide these details so the compiler's knowledge of the type struct task_struct is incomplete. >8. >9. } >10. int main() >11. { >12. execname(); >13. }
Remove del for email
"J. J. Farrell" wrote: > On Jun 7, 12:03 am, Pritam <chh @gmail.com> wrote: >> line 7: error: dereferencing pointer to incomplete type >> 1. #include<stdio.h> >> 2. #include<sys/stat.h>
Unknown include file - not part of the C standard. >> 3. #include<stdlib.h> >> 4. void execname() { >> 5. struct task_struct *my;
Undefined type. >> 6. my = find_task_by_id(getpid());
Undefined routine. >> 7. printf("%s",my->comm); error: deref ptr to incomplete type
Ignoring the "comment", my->comm undefined. >> 8. >> 9. } >> 10. int main()
int main(void) is better. >> 11. { >> 12. execname();
Failure to return a value. >> 13. } >> what's wrong with it > You haven't included whatever header(s) you need to define the > structure type task_struct. This structure isn't defined by the C > standard, so you need to look in the documentation for programming on > whatever OS you are using, or ask in a newsgroup which discusses > programming on that OS.
Above is a fairly detailed list. I may have missed something. -- <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt> <http://www.securityfocus.com/columnists/423> <http://www.aaxnet.com/editor/edit043.html> <http://kadaitcha.cx/vista/dogsbreakfast/index.html> cbfalconer at maineline dot net -- Posted via a free Usenet account from http://www.teranews.com
Pritam wrote: > line 7: error: dereferencing pointer to incomplete type > 1. #include<stdio.h> > 2. #include<sys/stat.h> > 3. #include<stdlib.h> > 4. void execname() { > 5. struct task_struct *my; > 6. my = find_task_by_id(getpid()); > 7. printf("%s",my->comm); error: dereferencing pointer to incomplete > type > 8. > 9. } > 10. int main() > 11. { > 12. execname(); > 13. } > what's wrong with it
It appears that you have no definition of struct task_struct in scope, so the compiler has no idea where the comm member is. Some tips: 1) Never post code with line numbers. That only makes it difficult for people who would like to help you, since they must edit out that extraneous garbage. Similarly, don't make code uncompilable by appending test like "error: dereferencing pointer to incomplete type" to lines. Make such things legal comments. 2) indent your code so it is readable. By including line numbers, you already told us you don't want the compiler to read your code. By refusing to indent your code you are telling us you don't want humans to read it either. 3) Don't expect reasonable answers about non-standard functionality. By including the non-standard <sys/stat.h> you will have caused many to stop reading right there. You *do* have a C question, and by dressing it in non-standard dress you may have shut yourself off from an answer. You could have asked your question in a way that avoided any reference to non-standard functionality. 4) When you do have a question about non-standard features, ask in newsgroups where it is appropriate. When you do ask, try to provide complete code. For example, the function getpid() is typically a POSIX or UNIX function, suggesting the kinds of newsgroups where it will be topical. However, the declaration for getpid() is typically found in <unistd.h>, which you did not include. The find_task_* family are, as far as I know, Linux kernel routines, which will not be topical outside of Linux mailing lists. If you have some other platform with that family, post appropriately. However, your question suggests that you are trying to skip some important steps (like learning C) which you ought not skip.
|
 |
 |
 |
 |
|