Date: Sat, 13 Jun 1998 11:59:19 -0700 From: Mike Smith <mike@smith.net.au> To: zhihuizhang <bf20761@binghamton.edu> Cc: hackers <freebsd-hackers@FreeBSD.ORG> Subject: Re: linker set defintion (ls_item) Message-ID: <199806131859.LAA00727@antipodes.cdrom.com> In-Reply-To: Your message of "Sat, 13 Jun 1998 15:56:13 EDT." <Pine.SOL.L3.93.980613155010.26627A-100000@bingsun1>
next in thread | previous in thread | raw e-mail | index | archive | help
>
> I am reading freeBSD source code concerning the linker set which I believe
> is a set of *addresses* of similar symbols. The linker set structure is
> defined in kernel.h as:
>
> struct linker_set {
> int ls_length;
> const void * ls_item[1];
> }
>
> The value of ls_item should be the address of an array of pointers.
No. ls_item is the first entity in an array of pointers. The linker
_set structure is prepended to the array, rather than pointing to it.
> Since
> the size of this array is not fixed, I wonder why it is not defined as:
>
> struct linker_set [
> int ls_length;
> const void ** ls_item;
> }
>
> This may have something to do with the C compiler. I hope some C expert
> can give me a hint. Thanks in advance.
Because the above is incorrect.
If you were dynamically allocating a linker_set structure, you would
do something like this:
lsptr = (struct linker_set *)malloc(sizeof(struct linker_set) +
(num_items - 1) * sizeof(void *));
This then lets you address items in the linker set thus:
iptr = lsptr->ls_item[item_number]
This technique takes advantage of the fact that C performs no
range-checking.
--
\\ Sometimes you're ahead, \\ Mike Smith
\\ sometimes you're behind. \\ mike@smith.net.au
\\ The race is long, and in the \\ msmith@freebsd.org
\\ end it's only with yourself. \\ msmith@cdrom.com
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806131859.LAA00727>
