i have seen a block of code which allocates memory pool. A line in the block of code says
*(char**) block = nextblock;
can any one help what is the intention of typecasting a char*
block as *(char**)
?
コードの読みやすさ以外に、そのような型キャストを行うべき理由は思いつきません。
ポインターの逆参照は許可されており、で呼び出さvoid**
れた my によって眉をひそめることさえありませんgcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52)
gcc -pedantic dereferencetest.c
struct StructTest {
char* ptr;
};
int main(void)
{
char* str = strdup("test");
char** ptr = &str;
void** vptr = ptr; // warning here
char* strRecycled = *vptr; // no warning on dereferencing
printf("str=[%s]", strRecycled);
{
struct StructTest val;
struct StructTest* structPtr = &val;
struct StructTest** structPtrPtr = &structPtr;
vptr = structPtrPtr; // warning here
structPtr = *vptr; // no warning on dereferencing
}
return 0;
}
無効なポインター型の割り当てと初期化に関する警告がありますが、逆参照の警告はありません。
dereferencetest.c:9: warning: initialization from incompatible pointer type
dereferencetest.c:20: warning: assignment from incompatible pointer type