エイリアシングに問題があります。私は以前にそれに直面していません。 Eclipse CDTを使用しています。 私はさまざまな解決策を読んだが、適切なものは見つけられなかった。警告!逆参照型のペーンドポインタは厳密なエイリアシング規則を破棄します[-Wstrict-aliasing]
私はだから私は、次のコードの平和を警告
型punnedポインタを参照解除することは、厳密なエイリアシング規則を破るだろう[-Wstrictエイリアシング]
を持っています
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
に間違った値があります。
してください!この問題を解決する手助けをしてください!
EDIT 私が間違っていたかを理解したい...構造my_rtppacketは、次のように定義されています
{
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"の定義を私たちに提供する必要があります。 –
私は、パックされたstruct(またはendianessの場合は2)が良いかどうか疑問に思います。または、おそらく構造体データからバッファを埋めるための関数を作成する... –
ところで、あなたは値が間違っていると思いますか? –