typedef void * variable;

This is a discussion on typedef void * variable; within the C Programming forums, part of the General Programming Boards category; What does this mean exactly? It's a variable type declared in a structure. Is this just a pointer variable? typedef ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    29

    Post typedef void * variable;

    What does this mean exactly? It's a variable type declared in a structure. Is this just a pointer variable?

    typedef void * variable;

    Any material explaining similar to the above code, that would help.
    Disk space: the final frontier

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    Think of it as a pointer that can point to any data type. The drawback is that you need to know what datatype its pointing to and typecast it before you can use it. For example:

    Code:
    void Print(void* DataPtr)
    {
        char* text = ((char*)DataPtr);
        cout << text;
    }
    
    int main()
    {
      char* mytext = "asdfasdf";
      Print((void*)mytext);
    }
    There isn't much you can do with it for straight up applications but for wrapper classes where the user needs more control over the application its a god.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    29
    Thanks for your explantion durban, that makes sense. I must add this is 'C Programming' and not 'C++ Programming'.
    Last edited by cblix; 11-06-2005 at 06:51 PM.
    Disk space: the final frontier

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by durban
    char* text = ((char*)DataPtr);
    As a note there is no need to cast a void* when assigning it to another pointer. That is a c++ requirement.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 09:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21