앨리어싱에 문제가 있습니다. 나는 전에 그것과 결코 대면하지 않았다. Eclipse CDT를 사용하고 있습니다. 다른 해결책을 읽었지만 나에게 적합한 해결책을 찾을 수 없었습니다.경고! dereferencing type-punned 포인터가 엄격한 앨리어싱 규칙을 위반합니다 [-Wstrict-aliasing]
나는 경고를 가지고 엄격한 앨리어싱 규칙 [-Wstrict 앨리어싱]
끊어집니다 타입 punned 포인터를 역 참조
그래서 다음 코드 평화 있습니다
을timestamp = st0 % 100000000; for (std::list<struct trace *>::iterator it = frame_list.begin(); it != frame_list.end(); ++it) { struct my_rtppacket *packet = NULL; packet = new struct my_rtppacket; packet->ts = (int32_t)((*it)->time * 1000000); packet->seq = count_seq; //In the following two strings I have the warnings :( *(uint16_t*) (packet->buf + 2) = htons(packet->seq); *(int32_t*) (packet->buf + 4) = htonl(packet->ts + timestamp); insert_data_to_list(packet); // This function inserts packets to list} }
packet->buf + 2
및packet->buf + 4
에는 잘못된 값이 있습니다.주세요! 이 문제를 해결하도록 도와주세요!
{ struct my_rtppacket { public: my_rtppacket():dump_ts(0), payloadlen(0),packetlen(0),ts(0), seq(0), seq_fr(0), frame_number(0), erase(NUM, INIT), path(NUM, INIT), create_time(0), alloc_time(0), before_create(0), sent_flag(0){} uint32_t dump_ts; /*timestamp of RTP dump. It is similar to timestamp of packet generation from the application*/ int payloadlen; int packetlen; int32_t ts; /*timestamp in RTP file*/ uint16_t seq; /* Sequеnce number in video sequence*/ int seq_fr; /* Sequеnce number in a frame*/ int frame_number; char buf[1600]; std::vector <path_t> erase; std::vector <path_t> path; //Declare a vector of path_type elements char frame_type[10]; int64_t create_time; int64_t alloc_time; int64_t before_create; int sent_flag; }; }
포인터 연산, 재 해석 캐스팅 등이 그늘에 보입니다. 그러나 반드시 "struct my_rptpacket"의 정의를 제공해야합니다. –
포장 된 구조체 (또는 endianess의 경우 2)가 더 좋을지 궁금합니다. 아니면 구조체 데이터에서 버퍼를 채우기 위해 함수를 만드는 것입니다 ... –
BTW, 어떻게 값이 잘못되었다는 것을 알 수 있습니까? –