作者Carbontube (碳管)
看板C_and_CPP
标题[问题] 请问要怎样在function中对2个array做初使化?
时间Sat Feb 28 14:55:59 2009
原本这样可以:
int n=100;
double *t
t = initialization(n)
:
double *intitaliztion(int n)
{
double *t;
t = (double*)calloc(n,sizeof(double));
// 下面就设定t array的内容
return t;
}
===
现在若想要对两个以上的array做初使设定:
int n= 100;
double *t, *y;
initialization(n, t , y);
void initialization(int n,double *t ,double *y)
{
t = (double*)calloc(n,sizeof(double));
y = (double*)calloc(n,sizeof(double));
//塞值进去t, y array中
return;
}
这样是不行的,debug mode是不会过,release mode会不正确
解决方法是把 calloc那行写在function外面。但我就想把配置那行
写在function中啊。。。
请问有无大牛知道要怎做呢,谢谢。
不要和我讲写两个function。。。。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.167.75.177
1F:推 TroyLee:参数要带 ** 02/28 15:01
2F:推 csihcs:for C++ : void init(int n,double *&t ,double *&y) 03/01 10:21
3F:→ csihcs:其余不变 03/01 10:21
4F:→ csihcs:for C : void init(int n,double **t , double **y) 03/01 10:22
5F:→ csihcs:init(n, &t , &y); 03/01 10:22
6F:→ csihcs:*t = (double*)calloc(n,sizeof(double)); 03/01 10:23
7F:推 aaa12345:for csihcs: if C++,t =(double*)calloc(n,sizeof(do.. 03/01 16:00
8F:→ aaa12345:u say "其余不变" sorry! sorry! u are right! 03/01 16:02