Generic Stack problem

S

Scamjunk

I have the following code for a generic stack implementation.

----------------
void Push(void *value, void *Stack, int *top)
{
if(!(IsFull(Stack, top)))
{
(*top)++;
Stack[*top] = *value;
}
}
-------------

and am getting the following error:

error C2036: 'void *' : unknown size

How do i overcome this? Any ideas?

TIA,
Scam.
 
V

Vladimir Oka

Scamjunk said:
I have the following code for a generic stack implementation.

----------------
void Push(void *value, void *Stack, int *top)
{
if(!(IsFull(Stack, top)))
{
(*top)++;
Stack[*top] = *value;

You're not allowed to dereference a `void *`.
 
C

CBFalconer

Scamjunk said:
I have the following code for a generic stack implementation.

----------------
void Push(void *value, void *Stack, int *top)
{
if(!(IsFull(Stack, top)))
{
(*top)++;
Stack[*top] = *value;
}
}
-------------

and am getting the following error:
error C2036: 'void *' : unknown size
How do i overcome this? Any ideas?

By not trying to store a void in an object of type void*

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
K

Kelsey Bjarnason

[snips]

void Push(void *value, void *Stack, int *top)
{
if(!(IsFull(Stack, top)))
{
(*top)++;
Stack[*top] = *value;
}
}
-------------

and am getting the following error:

error C2036: 'void *' : unknown size

Well... what is a void *? It's a pointer-to-void. What's a void? It is
a non-type. It has no size, no format, it is a black hole from which you
cannot read.

So what's your code do? It takes a void * parameter as value. It then
does:

Stack[*top] = *value;

Hmm. = *value. Assign whatever's in the memory pointed to by value...
but... value is a void pointer; it points to a void, an item with no size,
no actual type, no representation.

How do you expect the compiler to figure out the correct thing to do from
the code, which tells it to retrieve, literally, nothing?

You're going to have to cast, or handle typing a little better or a little
differently, etc.
 
S

Scamjunk

Got it!

this is the revised code -- for whatever it is worth.

void my_Push(void *value, void **Stack, int *top)
{
if(!(my_IsFull(Stack, top)))
{
(*top)++;
*(Stack + (*top)) = value;
}
}

it compiles alright now. Thanks for the replies.
 
R

Rod Pemberton

Scamjunk said:
I have the following code for a generic stack implementation.

----------------
void Push(void *value, void *Stack, int *top)
{
if(!(IsFull(Stack, top)))
{
(*top)++;
Stack[*top] = *value;
}
}
-------------

and am getting the following error:

error C2036: 'void *' : unknown size

How do i overcome this? Any ideas?

Normally, the exact type of 'Stack' and 'value' would be in your function
declaration. Let's take, for example, 'unsigned long' for each:

void Push(unsigned long *value, unsigned long *Stack, int *top)

However, since you used 'void *' and mentioned 'generic' routines, I suspect
you are trying to push and pop different types of values, and perhaps even
structures, onto the 'Stack'. If so, each type except void, can be
represented as an array of unsigned chars. You'll need to redo your generic
routines for unsigned chars (instead of 'void *'). Then you'll need to
convert the data to pushed or popped to unsigned chars, perhaps via casts or
via memcpy etc., before passing to the stack routines. You'll probably also
need to pass the length of each piece of data, since they will vary in size,
in terms of unsigned chars to the push and pop routines.

Make some changes. Try some stuff. Post some more code. IIRC, someone was
working on this about a month ago.


Rod Pemberton
 
A

Andrew Poelstra

Scamjunk said:
Got it!

this is the revised code -- for whatever it is worth.

void my_Push(void *value, void **Stack, int *top)
{
if(!(my_IsFull(Stack, top)))
{
(*top)++;
*(Stack + (*top)) = value;
}
}

it compiles alright now. Thanks for the replies.

Well, it's worth absolutely nothing, because non-Googlers have no idea
what you revised.

Please click on 'More Options' and 'Add Reply' to correctly quote context.
 
R

Rod Pemberton

Andrew Poelstra said:
Well, it's worth absolutely nothing, because non-Googlers have no idea
what you revised.

Please click on 'More Options' and 'Add Reply' to correctly quote context.

Requesting context is one thing. But, saying that non-Googlers have no idea
of what the prior posts were is absurd. I don't use Google. Heck, I don't
even use the high quality newservers provided by my ISP. I just never
bothered becuase it's so easy to find an open one. There are literally
thousands of open newservers in the US, EU, and Asia which are current and
have very good completion (i.e., they didn't loose any meassages). Please
stop spreading myths.

Rod Pemberton
 
A

Andrew Poelstra

Rod said:
Requesting context is one thing. But, saying that non-Googlers have no idea
of what the prior posts were is absurd. I don't use Google. Heck, I don't
even use the high quality newservers provided by my ISP. I just never
bothered becuase it's so easy to find an open one. There are literally
thousands of open newservers in the US, EU, and Asia which are current and
have very good completion (i.e., they didn't loose any meassages). Please
stop spreading myths.

Rod Pemberton

It's more of a motivation than a truth; I could see what he revised,
because my newsreader has a nice GUI with everything organized.

However, if the people who don't post context believe that it it's only
causing problems to a few people, they won't stop, and we're worse off.

But I agree that c.l.c is /not/ the place for me to be spreading myths.
 
C

CBFalconer

Andrew said:
Rod Pemberton wrote:
.... snip ...

It's more of a motivation than a truth; I could see what he revised,
because my newsreader has a nice GUI with everything organized.

However, if the people who don't post context believe that it it's
only causing problems to a few people, they won't stop, and we're
worse off.

Contrary to Pembertons claim, most usenet users simply cannot see
previous messages without unholy contortions, even assuming that
such messages ever arrived, and if so that they were not purged
after reading. So meaningless contextless blather is useless.
Nobody in their right mind would run around switching newsservers
to see the missing context.

Around here I connect to the newsserver, download the current crop
of traffic, disconnect, and read/answer/plonk etc. off-line. The
system works very well. It does require the occasional purge of
the complete message history to avoid infinitely growing files.
Meanwhile previously read messages are simply not displayed.
 
B

Ben Pfaff

CBFalconer said:
Contrary to Pembertons claim, most usenet users simply cannot see
previous messages without unholy contortions, even assuming that
such messages ever arrived, and if so that they were not purged
after reading.

"Most"? This sounds to me like nonsense.
If so, "most" users need to get a better newsreader.
 
R

Rod Pemberton

CBFalconer said:
Contrary to Pembertons claim, most usenet users simply cannot see
previous messages without unholy contortions,

I use MS Outlook Express - no unholy contortions.
Linux users use ? - no unholy contortions.
even assuming that
such messages ever arrived, and if so that they were not purged
after reading. So meaningless contextless blather is useless.
Nobody in their right mind would run around switching newsservers
to see the missing context.

A while back, you called some other guy a troll after four solid months of
posting. Without any hostility, you _really_ should look for another
newserver.
Around here I connect to the newsserver, download the current crop
of traffic, disconnect, and read/answer/plonk etc. off-line. The
system works very well. It does require the occasional purge of
the complete message history to avoid infinitely growing files.
Meanwhile previously read messages are simply not displayed.

Dialup? Sounds like you're off the grid too. Solar perhaps? Move towards
civilization, buy some "always on" broadband, fix your email client settings
or replace it, and connect to a better newserver. You give the impression
that you're in the dark ages. I mean it sounds like you're using Bitnet or
worse the ancient 1980's dial-in dial-out network Telenet.

If you're running Windows, are you using MS "Outlook Express" for your news
reader? If you're running Linux, are you using Mozilla's "Thunderbird" for
your news reader? If you're not running Linux or Windows, you're part of
the problem that you're experiencing.


Rod Pemberton
 
C

CBFalconer

Ben said:
"Most"? This sounds to me like nonsense.
If so, "most" users need to get a better newsreader.

I don't think you read the rest of my article. And I have yet to
see a monitor with infinite space on it, so that a reader can
maintain an article and its various predecessors as simultaneously
visible. And that is assuming the predecessors are or have ever
been available.
 
R

Richard G. Riley

CBFalconer said:
Contrary to Pembertons claim, most usenet users simply cannot see
previous messages without unholy contortions, even assuming that

More bullshit? <sniff> Yes indeedy.

"Most" : what a load of old coswallop. Ive used something 8 newsreaders
in the past 10 years and they all had thread context : even for google replies.
such messages ever arrived, and if so that they were not purged
after reading. So meaningless contextless blather is useless.

Since 90% of "no context included replies" are just a "thanks", I'm
amazed so many of your little clique get your panties in such a knot.
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top