cast 용법이 제대된것인지 궁금합니다.

글쓴이: 익명 사용자 / 작성시간: 목, 2002/11/14 - 8:42오전
#include
#include
typedef struct _node {
struct _node *pnode;
int a;
char b[20];
} node_t;
int main( int argc , char *argv[] )
{
int a;
node_t **pp, spot;
pp = malloc( sizeof( node_t ) );
((node_t*)pp)->a = 8;
strcpy( ((node_t*)pp)->b , "thisisTest" );
spot = *(node_t*)pp;
fprintf( stderr , "a is %d\n" , spot.a );
fprintf( stderr , "b is %s\n" , spot.b );
fprintf( stderr , "sizeof node is %d\n" , sizeof(node_t) );
free(pp);
return 0;
}
컴파일하면 정상적으로 작동하고,동작하지만,
2중포인터를 위에처럼 cast해서 사용한것이 합법적인지요?
Forums:
댓글 달기