From owner-freebsd-hackers Sat Jun 13 13:04:13 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA00488 for freebsd-hackers-outgoing; Sat, 13 Jun 1998 13:04:13 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from antipodes.cdrom.com (castles301.castles.com [208.214.167.1]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA00452 for ; Sat, 13 Jun 1998 13:04:03 -0700 (PDT) (envelope-from mike@antipodes.cdrom.com) Received: from antipodes.cdrom.com (localhost [127.0.0.1]) by antipodes.cdrom.com (8.8.8/8.8.5) with ESMTP id LAA00727; Sat, 13 Jun 1998 11:59:19 -0700 (PDT) Message-Id: <199806131859.LAA00727@antipodes.cdrom.com> X-Mailer: exmh version 2.0zeta 7/24/97 To: zhihuizhang cc: hackers Subject: Re: linker set defintion (ls_item) In-reply-to: Your message of "Sat, 13 Jun 1998 15:56:13 EDT." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 13 Jun 1998 11:59:19 -0700 From: Mike Smith Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > 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