libosmocore[master]: linuxlist.h: add llist_len()

Neels Hofmeyr gerrit-no-reply at
Wed Jan 11 14:36:46 UTC 2017

Patch Set 1:

> Why returning int if it's always positive value? Better use size_t
 > or other unsigned type.

I considered it, but then decided to keep int, as in the original implementation from some C file in libosmo-abis:

firstly, practical fact: if we want to count the len by iterating an llist that has more than INT_MAX elements, something is seriously wrong.

Coding convenience: it is painful / dangerous to compare signed and unsigned ints. We usually use int for iterators, indexes, list lengths, so it's convenient to return an int here. Also enables the caller to compare with negative values -- no idea why we'd want that, but is conceivable that it might be useful.

So I agree that it is wrong in the sense of type logic to return a signed value, but if we return unsigned, we need to add type casts and checks or use unsigned int for iterators everywhere... (which is a bit like saying "then we need to use the correct type for iterators everywhere")

unsigned is more "correct", but I wasn't certain enough to change it from the int return type I found. What do other reviewers think?

To view, visit
To unsubscribe, visit

Gerrit-MessageType: comment
Gerrit-Change-Id: Ic49adc7a346f5722bf624d7d3b4a735e4220ae15
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at>
Gerrit-HasComments: No

More information about the gerrit-log mailing list