Hi,
If i am to have a function to return a pointer of an unknown type, is this the right prototype for it?
Code:void *function( void *one, void *two );
Printable View
Hi,
If i am to have a function to return a pointer of an unknown type, is this the right prototype for it?
Code:void *function( void *one, void *two );
Yes. You are simply returning an address without any indication as to what type of data the address refers to.
but it can still be used right?
Probably with something like this.
char *s = NULL;
char *blah1, *blah2;
s = function(blah1, blah2);
Something like that :) You will want to use a typecast since function() is returning a NULL pointer:Quote:
Originally posted by dharh
Probably with something like this.
char *s = NULL;
char *blah1, *blah2;
s = function(blah1, blah2);
Code:s = (char *) function(blah1, blah2);
Im not sure thats necessary if you protoype it as a pointer.
> Something like that :) You will want to use a typecast since
> function() is returning a NULL pointer:
Slight correction here. It's not returning a NULL pointer, it's returning a VOID pointer. Null is a value of zero, meaning it points to nothing. A void pointer is a pointer who's type can be anything. Typecasting is not usually required in C when using void pointers. (Consider 'malloc'.)
Quzah.
You are absolutely correct. Simply a typographical error on my part.Quote:
Originally posted by quzah
> Something like that :) You will want to use a typecast since
> function() is returning a NULL pointer:
Slight correction here.
Typecasting a void * is actually -never- required in C... but C++ :(