sathya_me <sa*******@nomail.com> wrote:
Je***********@physik.fu-berlin.de wrote:sathya_me <sa*******@nomail.com> wrote:
As I was going through a set of past thread I have some doubts in that.
The link to the thread is:
http://groups.google.co.in/groups?hl...41afc61&rnum=1
I considered the void pointer is the correct way to use generic type
in C programming(correct me if I am wrong.)
In the above thread is not it possible to create a
function using void pointer (as Default User suggested)? No body said
yes or no to his suggestion. Am I misunderstanding the concept of
generic type and void pointer?
The original problem was that the OP (Walter L. Preuninger) wanted to
pass _only_ a void pointer to a funtion and then retrieve information
about the type of the variable of what that pointer was pointing to.
I don't find any intention (retrieve information of the void*) in the
OP's post and thread
which follows. I am still miss something?
(Is section 4.9 of FAQ covers above of your definition?)
To make sure we're talking about the same thing: I was refering to the
thread with the subject "Way to determine type of variable?" - at least
that's what I found under the URL you posted. And it starts with the
question
"Walter L. Preuninger II" wrote: I would like to write a generic procedure that will take string or numeric
variables. I can not think of a way to make this more clear except to show
what I want.
int i=7;
char *s="/etc/filesystems";
generic(i);
generic(s);
So what he was more or less looking for a way to give some argument of
unspecified type to a function and, if possible, have the function
detect the type from what it got. Now, the only kind of appropriately
unspecified type is a void pointer, but it's lacking the type informa-
tion needed to print its value, so the kind of generic function he was
looking for isn't possible.
with it;-). So, yes, a void pointer is as generic a pointer as it can
get, but as such it doesn't convey some often important bit of infor-
mation, the type of what's poined to, and if that is needed it must
be supplied by other means.
^^^^^^^^^^^
Any link or FAQ for *other means* (I did went through but I did not find
the above).
Other means just means that you have to pass not only a void pointer
to the function but also some information about the type of what that
pointer points to. That can be done e.g. by passing it an additional
integer, with the value telling the function something about the type,
or e.g. a printf()-kind of format string or whatever other method you
can come up with - you could also use a global variable that always
gets set before the function call to some value representing the type
of the void pointer (but that would probably a rather ugly design).
"Default User"'s proposal was one of the possible ways to do this by
passing the function a structure that holds both a void pointer and
an integer, indicating what kind of type the pointer is pointing to.
But I get the feeling that I am misunderstanding you, so could you
perhaps try to explain again what exactly your question is? I seem
to be too dense to get it;)
Regards, Jens
--
\ Jens Thoms Toerring ___
Je***********@physik.fu-berlin.de
\__________________________
http://www.toerring.de