all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Schwab <schwab@linux-m68k.org>
To: Qiang Guo <qguo@ualberta.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Quesition about Lisp_Vector
Date: Fri, 11 Nov 2011 09:59:53 +0100	[thread overview]
Message-ID: <m3aa83avau.fsf@hase.home> (raw)
In-Reply-To: <m21utfrx37.fsf@ualberta.ca> (Qiang Guo's message of "Thu, 10 Nov 2011 23:29:16 -0700")

Qiang Guo <qguo@ualberta.ca> writes:

> Hi, I'm new to devel aspect of Emacs. And I'm having a problem reading
> Emacs source code: in the definition of Lisp_Vector
>  struct Lisp_Vector
>   {
>     EMACS_UINT size;
>     struct Lisp_Vector *next;
>     Lisp_Object contents[1];
>   };
>
> why contents's size is fixed ?

Standard C89 doesn't have flexible array members, so this is using the
well known struct hack.

> And later when actually allocating space
>
>  nbytes = sizeof *p + (len - 1) * sizeof p->contents[0];
>
> I don't understand how this nbytes is calculated. why only (len-1)

Because one element is already included in struct Lisp_Vector.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



  reply	other threads:[~2011-11-11  8:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-11  6:29 Quesition about Lisp_Vector Qiang Guo
2011-11-11  8:59 ` Andreas Schwab [this message]
2011-11-11  9:01 ` Ken Raeburn
2011-11-12  3:42   ` Stephen J. Turnbull
2011-11-12  8:49     ` Eli Zaretskii
2011-11-12 15:45       ` Stephen J. Turnbull
2011-11-12 15:53         ` Eli Zaretskii
2011-11-13  1:02     ` Ken Raeburn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3aa83avau.fsf@hase.home \
    --to=schwab@linux-m68k.org \
    --cc=emacs-devel@gnu.org \
    --cc=qguo@ualberta.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.