6
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main()
{
uint32_t ip = 0;
printf("%s\n",inet_ntoa(*(struct in_addr *)ip));
return 0;
}
임시 변수를 선언하여이 작업을 수행하고 싶지 않습니다. 이 프로그램은 분할 오류를 발생시킵니다.uint32_t를 struct in_addr로 변환하는 방법은 무엇입니까?
struct in_addr {
uint32_t s_addr;
};
나는 바보 같은 짓을하고 있다는 것을 알고 있었다. – Bruce
어떻게하면 같은 줄에서 htonl을 할 수 있을까? – Bruce
결과는 정의되지 않은 구현입니다. 그것은 경고를 준다 : 오류 : 역 참조 포인터 'ip'가 strict-aliasing 규칙을 깨지 않는다. – jrwren