Thread: How to use void* as an arguement?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656

    How to use void* as an arguement?

    I was wondering how qsort works with the combination of typeSize and void* input. I want to do arithmetic, but I'm not totally sure how to work this out...I'm thinking I could do a switch( typeSize ) and then convert to the appropriate type based on that, but I wouldn't be able to distinguish the difference between an int and an unsigned int.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <assert.h>
    
    /*
    	I want the input to be void*..not long.
    */
    void hmmm( void *v, size_t typeSize )
    {
    	/*
    		void*.c: In function `hmmm':
    		void*.c:7: warning: dereferencing `void *' pointer
    		void*.c:7: error: invalid use of void expression
    	*/
    	*v = 5;
    }
    
    int main( void )
    {
    	int n = 4;
    	char c = 4;
    	
    	hmmm( &n, sizeof( n ) );
    	hmmm( &c, sizeof( c ) );
    	
    	assert( n == 5 );
    	assert( c == 5 );
    	
    	return 0;
    }
    Last edited by Kleid-0; 05-11-2005 at 06:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template arguement probelm.
    By King Mir in forum C++ Programming
    Replies: 8
    Last Post: 09-12-2007, 02:18 PM
  2. function with array arguement
    By timhxf in forum C Programming
    Replies: 5
    Last Post: 01-05-2007, 03:20 PM
  3. passing a vector as an arguement
    By gL_nEwB in forum C++ Programming
    Replies: 7
    Last Post: 05-13-2006, 10:11 PM
  4. function call as a 'case' arguement
    By rc7j in forum C Programming
    Replies: 2
    Last Post: 02-17-2002, 08:09 PM
  5. an intersting arguement
    By iain in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 01-21-2002, 01:39 AM