get processs name; error: dereferencing pointer to incomplete type

P

Pritam

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
 
J

J. J. Farrell

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.
 
B

Barry Schwarz

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
 
M

Martin Ambuhl

Pritam said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top