I don't understand a past thread (help)

S

sathya_me

friends,
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=en&lr=&ie=UTF-8&safe=off&th=e0ab565b941afc61&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?

--
"Combination is the heart of chess"
A.Alekhine
Mail to:
sathyashrayan25 AT yahoo DOT com
(remove the AT and DOT)
 
J

Jens.Toerring

sathya_me said:
friends,
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=en&lr=&ie=UTF-8&safe=off&th=e0ab565b941afc61&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.
And that's what is impossible, once you only have a void pointer
you can't figure out from that void pointer alone what knd of type
of variable it's pointing to. If you need that information you have
to pass it to the function together with the pointer. One of the
things proposed (by "Default User" aka Brian Rodenborn) was to use a
structure that contains the pointer as well as an integer with type
information and pass that to the function, which is of course a
possible solution (not getting a reply to a suggestion can, at least
in this group, usually be taken to mean that nobody finds any fault
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.
Regards, Jens
 
S

sathya_me

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?)
And that's what is impossible, once you only have a void pointer
you can't figure out from that void pointer alone what knd of type
of variable it's pointing to. If you need that information you have
to pass it to the function together with the pointer. One of the
things proposed (by "Default User" aka Brian Rodenborn) was to use a
structure that contains the pointer as well as an integer with type
information and pass that to the function, which is of course a
possible solution (not getting a reply to a suggestion can, at least
in this group, usually be taken to mean that nobody finds any fault
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).

--
"Combination is the heart of chess"
A.Alekhine
Mail to:
sathyashrayan25 AT yahoo DOT com
(remove the AT and DOT)
 
J

Jens.Toerring

sathya_me said:
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 said:
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.
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
 
D

Default User

sathya_me said:
friends,
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=en&lr=&ie=UTF-8&safe=off&th=e0ab5
65b941afc61&rnum=1

The guy who wanted function overloading. I vaguely remember it.
I considered the void pointer is the correct way to use generic type
in C programming(correct me if I am wrong.)

It is a way.
In the above thread is not it possible to create a
function using void pointer (as Default User suggested)?

Of course it's possible. Just not all that handy. Personally, I
consider a void pointer with type information preferable to a union
with type information, but both are ways to go about it. However, just
having a function with a void* won't do it for you.

void func(void *data)
{
/* what's data's type? nobody knows! */
}
No body said yes or no to his suggestion.

No doubt they were stunned by its brilliant simplicity (or simple
brilliancy). Or maybe so pedestrian and obvious it merited no comment.
Am I misunderstanding the concept of generic type and void pointer?

I don't know, are you? You'd need to ask some specific questions about
generic programming.



Brian Rodenborn
 
C

CBFalconer

sathya_me said:
.... snip ..

I considered the void pointer is the correct way to use generic
type in C programming(correct me if I am wrong.)

Take a look at hashlib.c and the usage examples, found at:

<http://cbfalconer.home.att.net/download/hashlib.zip>

for examples of the use of void* pointers and opaque data
objects. This separates the module interface from its
implementation as far as possible. As long as .h file is not
altered the .c file can be revised freely. Inasmuch as I wrote it
it obviously is a close approximation to perfection :) There has
only been one bug-report (fixed) since publishing it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top