What does void pointer actually mean?

Discussion in 'C Programming' started by Niu Xiao, May 3, 2006.

  1. Niu Xiao

    Niu Xiao Guest

    I saw a lot of codes like:

    void foo(void* arg)
    void bar(void** arg)
    f((void*)p)

    but what does void pointer mean in c? I just know it stands for generic
    pointer.

    thanks.
    Niu Xiao, May 3, 2006
    #1
    1. Advertising

  2. Niu Xiao <> writes:
    > I saw a lot of codes like:
    >
    > void foo(void* arg)
    > void bar(void** arg)
    > f((void*)p)
    >
    > but what does void pointer mean in c? I just know it stands for
    > generic pointer.


    Right, it's a generic pointer. I'm not sure what you're asking.

    "void" is a special type, an incomplete type that cannot be completed.
    You can't have an object of type void; a function that returns void
    doesn't return a value.

    Type "void*" is a pointer type that can point to any object. An
    object of type void* can hold a value of any pointer-to-object type.
    Any object type can be implicitly converted to void*, and vice versa.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, May 3, 2006
    #2
    1. Advertising

  3. Niu Xiao

    Jack Klein Guest

    On Wed, 03 May 2006 04:58:09 GMT, Keith Thompson <> wrote
    in comp.lang.c:

    > Niu Xiao <> writes:
    > > I saw a lot of codes like:
    > >
    > > void foo(void* arg)
    > > void bar(void** arg)
    > > f((void*)p)
    > >
    > > but what does void pointer mean in c? I just know it stands for
    > > generic pointer.

    >
    > Right, it's a generic pointer. I'm not sure what you're asking.
    >
    > "void" is a special type, an incomplete type that cannot be completed.
    > You can't have an object of type void; a function that returns void
    > doesn't return a value.
    >
    > Type "void*" is a pointer type that can point to any object. An
    > object of type void* can hold a value of any pointer-to-object type.
    > Any object type can be implicitly converted to void*, and vice versa.


    Of course you meant your last sentence above to read:

    A pointer to any object type can be implicitly converted to void*, and
    vice versa.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, May 3, 2006
    #3
  4. Jack Klein <> writes:
    > On Wed, 03 May 2006 04:58:09 GMT, Keith Thompson <> wrote
    > in comp.lang.c:

    [...]
    >> Type "void*" is a pointer type that can point to any object. An
    >> object of type void* can hold a value of any pointer-to-object type.
    >> Any object type can be implicitly converted to void*, and vice versa.

    >
    > Of course you meant your last sentence above to read:
    >
    > A pointer to any object type can be implicitly converted to void*, and
    > vice versa.


    Yes, thanks.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, May 3, 2006
    #4
  5. Niu Xiao

    Niu Xiao Guest

    Keith Thompson wrote:
    > Niu Xiao <> writes:
    >
    >>I saw a lot of codes like:
    >>
    >>void foo(void* arg)
    >>void bar(void** arg)
    >>f((void*)p)
    >>
    >>but what does void pointer mean in c? I just know it stands for
    >>generic pointer.

    >
    >
    > Right, it's a generic pointer. I'm not sure what you're asking.
    >
    > "void" is a special type, an incomplete type that cannot be completed.
    > You can't have an object of type void; a function that returns void
    > doesn't return a value.
    >
    > Type "void*" is a pointer type that can point to any object. An
    > object of type void* can hold a value of any pointer-to-object type.
    > Any object type can be implicitly converted to void*, and vice versa.
    >


    > Any object type can be implicitly converted to void*, and vice versa.

    This sentence tells everything, thanks.
    Niu Xiao, May 5, 2006
    #5
  6. Niu Xiao <> writes:
    > Keith Thompson wrote:

    [...]
    > > Any object type can be implicitly converted to void*, and vice versa.

    > This sentence tells everything, thanks.


    Except that it's wrong.

    Any pointer-to-object type (not any object type) can be implicitly
    converted to void*, and vice versa.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, May 5, 2006
    #6
    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. Ollej Reemt
    Replies:
    7
    Views:
    518
    Jack Klein
    Apr 22, 2005
  2. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    786
    The Real OS/2 Guy
    Oct 28, 2003
  3. ziwu

    What does this actually mean?

    ziwu, Aug 8, 2004, in forum: C Programming
    Replies:
    2
    Views:
    272
    William L. Bahn
    Aug 8, 2004
  4. Replies:
    5
    Views:
    824
    S.Tobias
    Jul 22, 2005
  5. Michael T. Richter

    What does this warning actually mean?

    Michael T. Richter, Aug 2, 2007, in forum: Ruby
    Replies:
    1
    Views:
    106
    Michael T. Richter
    Aug 2, 2007
Loading...

Share This Page