Generic Stack problem

Discussion in 'C Programming' started by Scamjunk, Apr 27, 2006.

  1. Scamjunk

    Scamjunk Guest

    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.
    Scamjunk, Apr 27, 2006
    #1
    1. Advertising

  2. Scamjunk

    Vladimir Oka Guest

    Scamjunk wrote:
    > 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 *`.

    > }
    > }
    > -------------
    >
    > and am getting the following error:
    >
    > error C2036: 'void *' : unknown size
    >
    > How do i overcome this? Any ideas?
    Vladimir Oka, Apr 27, 2006
    #2
    1. Advertising

  3. Scamjunk

    CBFalconer Guest

    Scamjunk wrote:
    >
    > 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/>
    CBFalconer, Apr 27, 2006
    #3
  4. [snips]

    On Thu, 27 Apr 2006 03:35:59 -0700, Scamjunk wrote:

    > 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.
    Kelsey Bjarnason, Apr 27, 2006
    #4
  5. Scamjunk

    Scamjunk Guest

    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.
    Scamjunk, Apr 28, 2006
    #5
  6. "Scamjunk" <> wrote in message
    news:...
    >
    > 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
    Rod Pemberton, Apr 28, 2006
    #6
  7. Scamjunk wrote:
    > 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.

    --
    "Every prime number in a series as a joke
    Made all the patterns clear when I took that final toke"
    - - Andrew Poelstra <http://www.wpsoftware.net/blog>
    Andrew Poelstra, Apr 28, 2006
    #7
  8. "Andrew Poelstra" <> wrote in message
    news:eop4g.83366$WI1.68175@pd7tw2no...
    > Scamjunk wrote:
    > > 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.
    >


    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
    Rod Pemberton, Apr 29, 2006
    #8
  9. Rod Pemberton wrote:
    > "Andrew Poelstra" <> wrote in message
    > news:eop4g.83366$WI1.68175@pd7tw2no...
    >> Scamjunk wrote:
    >>> 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.
    >>

    >
    > 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.

    --
    "Every prime number in a series as a joke
    Made all the patterns clear when I took that final toke"
    - - Andrew Poelstra <http://www.wpsoftware.net/blog>
    Andrew Poelstra, Apr 29, 2006
    #9
  10. Scamjunk

    CBFalconer Guest

    Andrew Poelstra wrote:
    > Rod Pemberton wrote:
    >

    .... snip ...
    >>
    >> 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.

    >
    > 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.

    --
    "Churchill and Bush can both be considered wartime leaders, just
    as Secretariat and Mr Ed were both horses." - James Rhodes.
    "We have always known that heedless self-interest was bad
    morals. We now know that it is bad economics" - FDR
    CBFalconer, Apr 29, 2006
    #10
  11. Scamjunk

    Ben Pfaff Guest

    CBFalconer <> writes:

    > 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.
    --
    "...what folly I commit, I dedicate to you."
    --William Shakespeare, _Troilus and Cressida_
    Ben Pfaff, Apr 30, 2006
    #11
  12. "CBFalconer" <> wrote in message
    news:...
    > Andrew Poelstra wrote:
    > > Rod Pemberton wrote:
    > >

    > ... snip ...
    > >>
    > >> 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.

    > >
    > > 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,


    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
    Rod Pemberton, Apr 30, 2006
    #12
  13. Scamjunk

    CBFalconer Guest

    Ben Pfaff wrote:
    > CBFalconer <> writes:
    >
    >> 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.


    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.

    --
    "Churchill and Bush can both be considered wartime leaders, just
    as Secretariat and Mr Ed were both horses." - James Rhodes.
    "We have always known that heedless self-interest was bad
    morals. We now know that it is bad economics" - FDR
    CBFalconer, Apr 30, 2006
    #13
  14. CBFalconer <> writes:

    > Andrew Poelstra wrote:
    >> Rod Pemberton wrote:
    >>

    > ... snip ...
    >>>
    >>> 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.

    >>
    >> 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


    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.
    Richard G. Riley, May 2, 2006
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Murat Tasan
    Replies:
    1
    Views:
    8,028
    Chaitanya
    Feb 3, 2009
  2. Replies:
    2
    Views:
    424
  3. Surinder Singh
    Replies:
    1
    Views:
    1,180
    Richard Bos
    Dec 20, 2007
  4. minlearn
    Replies:
    2
    Views:
    445
    red floyd
    Mar 13, 2009
  5. Ankur Arora
    Replies:
    1
    Views:
    558
    Michael Doubez
    Jun 26, 2009
Loading...

Share This Page