[comp.os.minix] A simple question

PL147744%TECMTYVM.BITNET@uicvm.uic.edu (Marcela Bonilla J.) (03/28/89)

Well, this is just a simple C question about the code of Minix.

Can anybody tell me what does this instruccion means ?

" r = (rp - proc) - NR_TASKS  "

rp is a pointer to a structure of type proc and proc is the table of
procedures... =) I passed two days trying to figure out what does that
instruction mean and I am still in the dark... If somebody has the
patiente to answer this question I will be real happy for that.

Thanks

May

ath@helios.prosys.se (Anders Thulin) (03/29/89)

In article <11762@louie.udel.EDU> PL147744%TECMTYVM.BITNET@uicvm.uic.edu (Marcela Bonilla J.) writes:
>Can anybody tell me what does this instruccion means ?
>
>" r = (rp - proc) - NR_TASKS  "
>
>rp is a pointer to a structure of type proc and proc is the table of
>procedures... =)

Quote:

	"If two pointers to objects of the same type are subtracted,
	the result is converted (by division by the length of the
	object) to an int representing the number of objects
	separating the pointed-to objects.  The conversion will in
	general give unexpected results, unless the pointers point to
	objects in the same array, since pointers, even to objects of
	the same type, do not necessarily differ by a multiple of the
	object length"

(rp - proc) produces the index of rp inside the table proc, that
is rp == proc[rp-proc].
-- 
Anders Thulin			INET : ath@prosys.se
ProgramSystem AB		UUCP : ...!{uunet,mcvax}!enea!prosys!ath
Teknikringen 2A			PHONE: +46 (0)13 21 40 40
S-583 30 Linkoping, Sweden	FAX  : +46 (0)13 21 36 35

gnf3e@babbage.acc.virginia.edu (Greg Fife) (03/30/89)

In article <405@helios.prosys.se> ath@helios.prosys.se (Anders Thulin) writes:
. . .
>(rp - proc) produces the index of rp inside the table proc, that
>is rp == proc[rp-proc].

I think you want rp == &(proc[rp-proc]).  Rp and proc are pointers,
and the construction pointer[index] is the type of what the pointer 
points to (or, as the Pascal programmer would say, it's the element at
that index in an array)

                                       
______________________________________________________________________

Greg Fife                            "A king is but a foolish
(804) 924-7743                        laborer/ who wastes his blood
gnf3e@virgnia.edu                     to be another's dream."