Generic pointer

This is a discussion on Generic pointer within the C Programming forums, part of the General Programming Boards category; Hi. I'm trying to do a recursive data union in C, but I'm not sure if I'm doing it right ...

Generic pointer

Hi. I'm trying to do a recursive data union in C, but I'm not sure if I'm doing it right at all.
In english the data is:
"A boolean expression (bexpr) is one of: And, Not, Or, Var."
"And has: bexpr left, bexpr right."
"Or has: bexpr left, bexpr right."
etc.
Var only has char[] name, so everything must termiante at a Var somewhere.

In java this might be done with an interface "bexpr" and then 4 classes, which have objects of type bexpr.

How can I achieve similar effect in C and operate on the data?

Right now I'm thinking of doing this with void pointers but I do not know if this is right at all.
Here's a snippet:

I'm not sure what it is you're trying to do, but it seems way too complicated. You're just making a list of expressions, and their definition is basically a list of expressions and a direction? Am I understanding that right? Be lazy, use strings. Pick a letter (say A for AND, one for OR... you get the idea) and there you go.

Now you didn't show us any example of what it is your data is supposed to look like. Looking at your definition of AND and OR, they're identical. So that doesn't help us either. But just do it the easy way and use a string. If everything ends at a "VAR", then you do whatever it is:

"ALRVmyvarname";

Here you have "AND" "LEFT" "RIGHT" "VAR" "myvarname". Which like I said, is as close to your definition of "AND" above that I can decypher.

Now make a union and have it basically just a list of every single data type you feel like making, or use a void pointer. Either way you're still going to need to make a bunch of stuff to store and retrieve things out of your blobs.