get processs name; error: dereferencing pointer to incomplete type

Discussion in 'C Programming' started by Pritam, Jun 7, 2007.

  1. Pritam

    Pritam Guest

    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
    Pritam, Jun 7, 2007
    #1
    1. Advertising

  2. On Jun 7, 12:03 am, 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


    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.
    J. J. Farrell, Jun 7, 2007
    #2
    1. Advertising

  3. On Thu, 07 Jun 2007 07:03:08 -0000, 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;


    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
    Barry Schwarz, Jun 7, 2007
    #3
  4. Re: get processs name; error: dereferencing pointer to incompletetype

    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.
    Martin Ambuhl, Jun 7, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven

    dereferencing pointer to incomplete type

    Steven, Jan 7, 2006, in forum: C Programming
    Replies:
    5
    Views:
    716
    Flash Gordon
    Jan 9, 2006
  2. friend.05
    Replies:
    0
    Views:
    308
    friend.05
    Nov 22, 2006
  3. friend.05
    Replies:
    8
    Views:
    645
    santosh
    Nov 22, 2006
  4. David Mathog
    Replies:
    3
    Views:
    701
    Chris Torek
    Jul 5, 2007
  5. Anuz
    Replies:
    6
    Views:
    2,348
Loading...

Share This Page