Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #66004

Re: Allocating memory styles

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Allocating memory styles
Date 2015-07-20 16:40 +0100
Organization A noiseless patient Spider
Message-ID <87zj2q6dnn.fsf@bsb.me.uk> (permalink)
References <0591b244-c066-4714-afad-3ba8db4a8676@googlegroups.com> <moiqt2$5i5$1@dont-email.me> <49e112fe-0bfc-4231-b2d6-86e42d7e30b4@googlegroups.com>

Show all headers | View raw


janus <emekamicro@gmail.com> writes:

Your quoting is still wrong.  This message had three copies of the post
you are replying to!

> Sorry that I didn't reproduce the whole code and the typos. I have the
> code below.Everything, I didn't pen a single one except to copy and
> paste. I have noticed that most of you have issues reading pasted
> codes.  Is there a way I could improve?

Not sure what you mean by that.  The code you posted before confused p
and P but was accurate enough for an educated guess (i.e. my explanation
stands).  Given that what you post below is a little different, I think
you need to check if your cut and paste is working as you expect.

> struct String { 
>               const void * class; 
>               char * text;
>               };

This is as I thought.  p points to a structure with a pointer as the
first element.

<snip>
>         const struct Class * class = _class; 
>         void * p = calloc(1, class --> size);
>         assert(p); 
>         * (const struct Class **) p = class;

Apart from the --> and (p rather than P) this is what you posted
before.  Does my explanation not help at all?

Since _class is a void *, and the target of the assignment is also a
void * I might have written *(const void **)p = _class; but then again I
think I would try to avoid having quite so many void *s around in the
first place.

<snip>
-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Allocating memory styles janus <emekamicro@gmail.com> - 2015-07-20 05:36 -0700
  Re: Allocating memory styles Noob <root@127.0.0.1> - 2015-07-20 14:53 +0200
    Re: Allocating memory styles janus <emekamicro@gmail.com> - 2015-07-20 07:23 -0700
      Re: Allocating memory styles Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-20 16:40 +0100
        Re: Allocating memory styles janus <emekamicro@gmail.com> - 2015-07-20 12:19 -0700
  Re: Allocating memory styles Richard Heathfield <rjh@cpax.org.uk> - 2015-07-20 14:07 +0100
  Re: Allocating memory styles Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-20 14:18 +0100
  Re: Allocating memory styles jt@toerring.de (Jens Thoms Toerring) - 2015-07-20 13:47 +0000
    Re: Allocating memory styles Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-20 15:21 +0100
  Re: Allocating memory styles Johann Klammer <klammerj@NOSPAM.a1.net> - 2015-07-20 16:27 +0200
  Re: Allocating memory styles luser droog <luser.droog@gmail.com> - 2015-07-20 12:34 -0700
    Re: Allocating memory styles Keith Thompson <kst-u@mib.org> - 2015-07-20 14:00 -0700
      Re: Allocating memory styles luser droog <luser.droog@gmail.com> - 2015-07-20 20:29 -0700
        Re: Allocating memory styles raltbos@xs4all.nl (Richard Bos) - 2015-07-22 15:21 +0000
    Re: Allocating memory styles janus <emekamicro@gmail.com> - 2015-07-20 14:13 -0700
  Re: Allocating memory styles "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-20 14:54 -0700
    Re: Allocating memory styles "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-20 14:57 -0700

csiph-web