-2
我對結構中的指針感到非常困惑。 我有一段代碼,這一點我沒有完全理解的是, 代碼:結構指針
typedef struct{
int fildes // basic file descriptor
char* location // location would be somewhere in /dev/tty*
}context0; // structure named 'context' containing the 2 elements above.
context0 someContext; // create a context struct
process(&readLocation); // takes reference from the function 'readlocation'
// i do not know what this process function does.
uint_16_t readLocation(int8_t *buffer, int16_t n, SomeContext){ // buffer pointer, n size read, and fidles
context0 foo = *(context0*) SomeContext; // ???? What Is Going ON right here ????
return read(foo.fd, buffer, n);
}
我已經更改了名字,但它的代碼,我不完全理解的。
一些問題:
因爲
readLocation
功能作爲引用傳遞它應該不能被定義爲void*
?面前的uint_32_t
主要問題:
context0 foo = * (context0*) SomeContext;
做什麼?
這不是C++代碼的一個有效一塊分。 'SomeContext'應該是一個類型或變量。如果它是一個變量,什麼是ts類型? –
someContext是一個context0類型的結構,如果anotherContext被添加someContext可以被看作是串行輸入的上下文,而另一個上下文將是串行輸出,其中將被寫入 – iBeyondPower
否則:問題1:否,任何類型的函數都可以作爲參數傳遞。問題2:它看起來像指向類型'context0 *'的轉換,並且是一個解引用。 (但正如我所說,這不是一個有效的代碼。) –