Marc Nieper-Wißkirchen wrote: > gl_list_iterator_t i = gl_list_iterator (list); > struct foo *elt; > while (gl_list_iterator_next (&i, (const void **) &elt, NULL)) > ++elt->bar;
This cast is dangerous: It silences the warning "passing argument 2 of 'gl_list_iterator_next' from incompatible pointer type", and is (AFAICS) a violation of the C strict-aliasing rule [1]. > So to make my original code portable C, I would have to code > > ... > const void *e; > while (gl_list_iterator_next (&i, &e, NULL)) > { > struct foo *foo = (void *) e; > ++foo->bar; > } Right, this is the way it should be written. > The const typecast is, unfortunately, still needed to silence compiler > warnings as the Gnulib list API suffers a bit from const-poisoning when the > actual elements are pointers actually non-const objects. Yes. The element type could be 'const void *' everywhere or 'void *' everywhere. Since the generic list code does not write to these pointers, I chose 'const void *'. Bruno [1] https://stackoverflow.com/questions/98650/what-is-the-strict-aliasing-rule