<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div><br></div><div><br></div><div>On Fri, Apr 26, 2019, at 10:57, Rémi Denis-Courmont wrote:<br></div><blockquote type="cite" id="qt"><div>Hi,<br></div><div><br></div><div>The respective structure layouts will in practice match in any real-life ABI, so accessing the scalar members will work.<br></div><div><br></div><div>Whether it works for the pointer values though... In my understanding, that is an open area of academic research on programming language. In other words, people do not know and we cannot rely on compilers to get this right until (maybe) a future version of ISO C clarifies it.<br></div></blockquote><div><br></div><div>So, for p_next, it is safer to always use a data pointer and use container_of to get the frame pointer, right ?<br></div><div><br></div><blockquote type="cite" id="qt"><div>If you are bored, search for articles on C pointer provenance.<br></div></blockquote><div><br></div><div><br></div><blockquote type="cite" id="qt"><div><br></div><div class="qt-gmail_quote"><div>Le 26 avril 2019 10:47:37 GMT+03:00, Thomas Guillem <thomas@gllm.fr> a écrit :<br></div><blockquote style="margin-top:0pt;margin-right:0pt;margin-bottom:0pt;margin-left:0.8ex;border-left-color:rgb(204, 204, 204);border-left-style:solid;border-left-width:1px;padding-left:1ex;" class="qt-gmail_quote"><pre class="qt-k9mail"><div>Question following my remark on the "[PATCH 00/17] RFC Split block_t into 2 different data containers" thread:<br></div><div><br></div><div> "- Code duplication between data.c and frame.c and also between data_helper.h and frame_helper.h: This code is far from trivial and should not be duplicated. We don't want to fix 2 files each time we need to fix a bug. The only way I see to solve this issue is to include vlc_data_t from vlc_frame_t and have generic vlc_data_t functions working with vlc_frame_t."<br></div><div><br></div><div>I wonder if it is possible to include vlc_data_t from vlc_frame_t without renaming all variables (in order to avoid a s/frame->p_buffer/frame->data.p_buffer/ change). Actually, it is possible in C by using anonymous unions and structs but is it allowed ?<br></div><div><br></div><div>cf. <a href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Type-punning">https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Type-punning</a><br></div><div><br></div><div>PS: ISO C++ prohibits anonymous structs so we will have to rename all C++ code that touch vlc_frame_t<br></div><div><br></div><div>Here is a sample to show what I would to do in VLC:<br></div><div><br></div><div>#include <stdlib.h><br></div><div>#include <stdio.h><br></div><div>#include <assert.h><br></div><div>#include <stdint.h><br></div><div>#include <inttypes.h><br></div><div><br></div><div>#define DATA_MEMBERS \<br></div><div> uint8_t *buf; \<br></div><div> size_t size; \<br></div><div> size_t maxsize; \<br></div><div> void *start; \<br></div><div><br></div><div>struct data {<br></div><div> DATA_MEMBERS<br></div><div> struct data *next;<br></div><div>};<br></div><div><br></div><div>struct frame<br></div><div>{<br></div><div> union<br></div><div> {<br></div><div> struct data d;<br></div><div>#ifndef __cplusplus<br></div><div> /* ISO C++ prohibits anonymous structs*/<br></div><div> struct {<br></div><div> DATA_MEMBERS<br></div><div> struct frame *next;<br></div><div> };<br></div><div>#endif<br></div><div> };<br></div><div><br></div><div> int64_t pts;<br></div><div> int64_t dts;<br></div><div>};<br></div><div><br></div><div><br></div><div>static void data_do_something(struct data *data)<br></div><div>{<br></div><div> data->buf += 10;<br></div><div> data->size -= 10;<br></div><div>}<br></div><div><br></div><div>static inline void frame_do_something(struct frame *frame)<br></div><div>{<br></div><div> data_do_something(&frame->d);<br></div><div>}<br></div><div><br></div><div>static void frame_do_specific_thing(struct frame *frame)<br></div><div>{<br></div><div> frame->buf -= 10;<br></div><div> frame->size += 10;<br></div><div>}<br></div><div><br></div><div>static void frame_print(struct frame *frame)<br></div><div>{<br></div><div> fprintf(stderr, "frame: data: %p %zu/%zu vs "<br></div><div> "%p %zu/%zu, pts: %" PRId64 "\n",<br></div><div> frame->d.buf, frame->d.size, frame->d.maxsize,<br></div><div> frame->buf, frame->size, frame->maxsize, frame->pts);<br></div><div>}<br></div><div><br></div><div><br></div><div>int main(void)<br></div><div>{<br></div><div> struct frame frame;<br></div><div> frame.d.size = frame.d.maxsize = 42;<br></div><div> frame.d.start = malloc(frame.d.size);<br></div><div> frame.d.buf = (uint8_t *) frame.d.start;<br></div><div> frame.d.next = NULL;<br></div><div> assert(frame.d.buf);<br></div><div> frame.pts = frame.dts = 72;<br></div><div><br></div><div> frame_print(&frame);<br></div><div> frame_do_something(&frame);<br></div><div> frame_print(&frame);<br></div><div> frame_do_specific_thing(&frame);<br></div><div> frame_print(&frame);<br></div><div><br></div><div> frame.next = &frame;<br></div><div> frame.d.next = &frame.d;<br></div><div><br></div><div> free(frame.d.start);<br></div><div> return 0;<br></div><div>}<hr>vlc-devel mailing list<br></div><div>To unsubscribe or modify your subscription options:<br></div><div><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></div></pre></blockquote></div><div><br></div><div>-- <br></div><div>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté. <br></div><div>_______________________________________________<br></div><div>vlc-devel mailing list<br></div><div>To unsubscribe or modify your subscription options:<br></div><div>https://mailman.videolan.org/listinfo/vlc-devel<br></div></blockquote><div><br></div></body></html>