作者ckaha (★閃亮數學推理★)
看板EE_DSnP
標題[問題] C++的pointer丟給C function
時間Mon Jun 2 00:04:01 2008
as title
我在.c檔
handle(unsigned* getInput,unsigned* numGate){
numGate[0] =1;
...
getInput = (unsigned*)malloc(sizeof(unsigned)*10);
getInput[0] =2;
...
}
.cpp
int main(){
...
unsigned *getInput;
unsigned numGate[3];
handle(getInput,numGate);
...
}
numGate 可以正確的拿到數值
可是 getInput卻不行
是因為 malloc 挖出來的是在stack?
--
所說的話,必須是從未殺過人的人才有資格說,
未免流於太過天真的夢想。
但是,和事實比起來…我比較喜歡天真的夢想。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.225.151.232
1F:推 ric2k1:這個可能要回去複習一下 call-by-value & call-by-pointer 06/02 00:12
2F:→ ric2k1:的差別... 06/02 00:12
3F:→ ric2k1:還有, unsigned *n[3] 傳給 unsigned* ? 06/02 00:12
4F:→ ckaha:阿 打錯 沒有* XD 06/02 00:35
※ 編輯: ckaha 來自: 125.225.151.232 (06/02 00:36)