Newsgroups: fj.lang.c
Path: galaxy.trc.rwcp.or.jp!coconuts.jaist!wnoc-tyo-news!infoweb-news!news.fukuoka.infoweb.or.jp!newshost.ryukyu.ad.jp!sour!merope!void
From: void@merope.opus.or.jp (Kusakabe Youichi)
Subject: Re: [Q] error in malloc
Message-ID: <1996Jul24.162821.22508@merope.opus.or.jp>
Organization: Macintosh User Group PLEIADES in opus (Okinawa Personal Unix Society)
X-Newsreader: TIN [version 1.2 PL0]
References: <YAGISITA.96Jul24192049@titan03.titan.info.eng.niigata-u.ac.jp>
Date: Wed, 24 Jul 1996 16:28:21 GMT
Lines: 52
Xref: galaxy.trc.rwcp.or.jp fj.lang.c:2633
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.lang.c&nb=2633&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.

Katunori Yagishita (yagisita@titan.info.eng.niigata-u.ac.jp) wrote:
:  $B$3$l$r%3%s%Q%$%k$7$F<B9T$9$k$H!"(Bsegmentation fault $B$,$G$^$9!#(B
:  $B%G%P%C%,$GD4$Y$?$H$3$m!"(Bcalloc$BCf$N(B malloc $B$G$R$C$+$+$C$F$$$^$7$?!#(B

$B$=$j$c$=$&$G$7$g$&!#%G%P%C%,!<$r;H$&A0$K%W%m%0%i%`$rFI$_D>$9JJ$r$D$1$k$Y$-$G$9!#(B

#include <stdlib.h>

#define SIZE0100
#define SIZE150
#define SIZE220

void subroutine()
{
    float **aa;
    float *x, *y;
    int   i;
     ...
    aa = (float **)calloc(SIZE0, sizeof(float *));
    for (i = 0; i < SIZE0; i++)
        aa[i] = (float *)calloc(SIZE1, sizeof(float));
    x = (float *)calloc(SIZE2, sizeof(float));
    y = (float *)calloc(SIZE2, sizeof(float));
   ...
}
$B$G$$$$$N$G$O(B? ($B2?$r$d$j$?$$$N$+$o$+$i$J$$$1$I(B)

: $B5-21NN0h$,$?$j$J$$$;$$$+$H;W$$!"$G$-$k$@$15-21NN0h$N@aLs$r$7$?$j!"(B

$B$=$s$J$3$H$^$G5$$K$G$-$k$s$@$C$?$i!"$=$NA0$K(B
$B!V(Bmalloc()$B!"(Bcalloc()$B$NLa$jCM$OI,$:%A%'%C%/$9$k$3$H!W$r<BA)$7$F$/$@$5$$!#(B
(NULL$B$+$I$&$+$r(B)


$B$G!"$5$i$K$=$l0JA0$K!"(B100$B$@$N(B50$B$@$N$$$&KbK!$N?t;z$rD>@\=q$/$3$H$O$$$1$^$;$s!#(B
$BI,$:(B#define$B$7$F$+$i;H$C$F$/$@$5$$!#(B

$B$D$$$G$K!"(Bdouble$B$K$7$J$$$G(Bfloat$B$K$7$?M}M3$O(B?
$B5-21NN0h$N@aLs$J$i0UL#$,$"$j$^$9$,!"$G$b$;$$$<$$(B2$BG\$7$+JQ$o$i$J$$$s$G$9$h!#(B

:  UNIX$B>e$GF0$/?'!9$J%"%W%j%1!<%7%g%s$r(BC$B$G=q$-$?$$$H;W$C$F$$$^$9$,!"2?$+(B
: $BNI$$;29M=q(B($BFC$K(BUNIX$B8GM-$N%i%$%V%i%j$K$D$$$F$J$I(B)$B$r8f?dA&2<$5$$!#(B

K&R$B$N!V(BProgramming Language C$B!W$G=<J,$G$7$g$&!#(B
2nd Edition$B$J$i%i%$%V%i%j!<4X?t$b=P$F$$$^$9!#(B
$B$[$s$H$&$K!V(BUNIX$B8GM-!W$N4X?t$,CN$j$?$$$J$i(BUNIX$B$N%^%K%e%"%k$r8+$l$P(B
$B:Q$`OC$G$9!#(B

  $B%X(B_$B%X(B   ------------------------
$B%_!&!&(B $B%_(B  void@merope.opus.or.jp
 (  $B!k(B )$B!A(B            $BF|2<ItM[0l(B
----------------------------------
