Thread: void *

  1. #1

    void *

    Hi. I've recently seen the use of "void *" in functions and i'm trying to figure out how it all works. If a function accepts 'void *' as a parameter that means i can pass in a pointer to anything i want, right? Like:

    void Func(void * ThisPtr)
    //do something with ThisPtr

    int Num = 1;
    char Array[10];
    struct AStruct
    int a, b, c;


    My compiler accepts that but i want to understand how it works. How can i determine the scope of what the ThisPtr points to? Like if i wanted to use fwrite of something in the Func(void *) function, how could i get the size of what i passed in (besides passing it in as another parameter...)?

    Could memory be allocated in function Func() like this?

    ThisPtr = new char[6];

    Or something? How could something like that be done?

    Sorry for all the questions but once i get it in my head that i want to know something, i want to know all about it.

  2. #2
    Evil Member
    Join Date
    Jan 2002
    Using void pointers in that manner is a good way to get a core dump. The type of a pointer dictates the length of the variable it denotes, so a void* is just an address, nothing more. There are a few good uses for void*'s, but that is getting into some advanced concepts, like pseudo pointers and funky casting.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  3. game window rejected painting !
    By black in forum Windows Programming
    Replies: 4
    Last Post: 03-27-2007, 01:10 AM
  4. msvc just ate one of my source files
    By Eber Kain in forum C++ Programming
    Replies: 6
    Last Post: 07-01-2004, 05:40 AM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM