From: chik@icot.or.jp (Takashi Chikayama)
Newsgroups: fj.lang.c
Subject: Re: Type of functions that return a pointer to self
Date: 16 Apr 92 01:29:46 GMT
	<FURUTA.92Apr13145244@srarc2.sra.CO.JP> <7173@coins.is.tsukuba.ac.jp>
Reply-To: chikayama@icot.or.jp
Distribution: fj
Organization: Institute for New Generation Computer Technology, Tokyo, Japan.

ICOT $B$N6a;3$G$9(B.

 |C $B$G<+J,$HF1$8$h$&$J4X?t$X$N%]%$%s%?$rJV$94X?t$C$F(B, $B$I$&=q$1$PNI$$$N$G(B
 |$B$7$g$&(B.  $B=q$-$?$$$N$O(B:
 |
 |	  typedef functype (functype *)();
 |
 |$B$NITF0E@$K(B$B$J$C$F$$$k$h$&$J$b$N$J$s$G$9$,(B.

$B$H$$$&;d$N<ALd$KBP$7(B, $B%U%)%m!<$r$"$j$,$H$&$4$6$$$^$7$?(B.

$B8EED$5$s$+$i(B$B$O(B:

 |  $B8EED!w(BSRA$B$H?=$7$^$9!#%-%c%9%H$r;H$C$FNI$$$J$i!"(B
 |
 |	  typedef void (voidfunc *)();
 |	  typedef voidfunc (functype *) ();
 |
 |$B$H$7$F$*$$$F!"(B
 |
 |	  functype f = $B=i4|CM(B;
 |	  while (1) f = (functype) (*f)();
 |
 |$B$G9=$o$J$$$N$G$O!)(B

$B$H$$$&8fDs0F$r$$$?$@$-$^$7$?(B.  $B$3$N(B (voidfunc *) $B$J$I$O(B (* voidfunc) 
$B$NI.$N8m$j$G$9$h$M(B.  $B$=$l$H(B, $B$I$&$;%-%c%9%H$9$k$N$J$i(B, $B0lCJ$@$1:F5"Dj(B
$B5A$rE83+$7$?$h$&$J=q(B$B$-J}$r$9$kI,MW$O$J$/(B, $BC1$K(B:

	typedef void *(* functype)();

$B$H$G$b$7$F$*$1$PNI$$$o$1$G$9$h$M(B.  $B$o$6$o(B$B$6(B void $B$G$O$J$/(B void * $B$rJV(B
$B$94X?t$K$7$?$N$O(B, $B<0$NCf$K(B void $B$,=P$F$/$k$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