On Sat, Mar 06, 2021 at 04:43:21PM +0000, Ramsay Jones wrote: > On 06/03/2021 10:05, Luc Van Oostenryck wrote: > > Change this, so that this function returns the total number of > > entries in the list, much like it's done for snprintf(). > > But this requires setting max == 0, right? This isn't documented. No no, there is nothing special with max == 0 at the interface level. If the list contains 3 elements but you're only interested in the cases it contains 2, you now call: ... array[2]; int nbr = linearize_ptr_list(list, array, 2); and it'll only fill 2 elements but it will return 3, so can you write: if (nbr == 2) { ... do stuff ... } IOW, it returns the number of elements that would have been written to the array if 'max' would have been infinite. Previously, it would have returned 2 because the return value was capped to 'max' / it returned he number of elements written. So you had no idea if the list effectively contained only 2 elements of if there was some more and so you had to call it with one extra element to check this: ... array[3]; int nbr = linearize_ptr_list(list, array, 3); if (nbr == 2) { ... } Thanks for noticing all these typos, -- Luc