[問題] struct call by reference

作者: MaxHaru (懂得放手..才是王道)   2016-11-12 17:49:41
開發平台(Platform): (Ex: Win10, Linux, ...)
8051
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
C51
問題(Question):
請問如何透過call by reference將struct中的pointer member傳給function
例如:
typedef struct _AA
{
unsigned char Addr;
unsigned char bIndex;
unsigned char bLenAddrW;
unsigned char *pDatAddrW;
unsigned char bFlag; //bit0: Notify Busy
//bit1: CmdByte Get
//bit2: Address Write
}_AAA;
unsigned char Dat[10];
void func1(unsigned char*pLenAddrW, unsigned char**ppDatAddrW)
{
*pLenAddrW = aaa;
*ppDatAddrW = Dat;
}
void main(void)
{
_AAA AAA;
_AAA*pAAA = &AAA;
func1(???, ???); //請問要怎麼透過pAAA將struct member的Address傳給func1??
}
作者: stupid0319 (徵女友)   2016-11-12 18:18:00
func1(&(pAAA->bLenAddrW),&(pAAA->pDatAddrW));
作者: MaxHaru (懂得放手..才是王道)   2016-11-12 20:52:00
明白了, 十分感謝..
作者: azter (Yilin)   2016-11-15 07:49:00
1F, 餵給func1的第一個參數多了“&”?
作者: hunandy14 (Charlott.HonG)   2016-11-15 16:27:00
關鍵字 傳參考
作者: LPH66 (-6.2598534e+18f)   2016-11-15 21:50:00
>azter 原 PO 就是要傳指標進去改值>hunandy14 純 C 的話沒有傳參考這回事喔, 只能這麼做

Links booklink

Contact Us: admin [ a t ] ucptt.com