I was watching a video on the Linux kernel moving to C99 or C11 possibly and the video was looking at an example for why they are going to do this.
I kept seeing a function being called like this:
list_for_each_entry(pos, &head, member) {
/* this code gets run for each entry? */
}
I've never seen something like this before in C or C++. However, as a Ruby programmer this makes sense to me because I'm used to doing something like this:
arr.each do |item|
# do something with the item
end
arr.each { |item| single_line_of_code_here }
I never knew that C had this ability? I was trying to learn more about this and my guess is this isn't a function but maybe a macro? Can someone explain to me what's happening here?
Edit: Documentation for this function here: https://www.kernel.org/doc/htmldocs/kernel-api/API-list-for-each-entry.html