Click here to Skip to main content
15,606,999 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
for (auto entry : directory_object->HashBuckets)
		if (entry == NULL)

		if (success == true)
i tried a lot of foreach loops non of them has worked.
am re - writing my kernel driver from c++ to C

What I have tried:

#define for_each_item(item, list) \
    for(T * item = list->head; item != NULL; item = item->next)

for_each_item(auto entry, directory_object->HashBuckets) {

and id didn't work i need a working for each loop for C couldn't find
Updated 27-Jan-19 21:30pm
Richard MacCutchan 28-Jan-19 4:15am    
You cannot use C++ constructs (foreach, templates, C++ constants etc.) in C code. Especially not in kernel code where the rules are much more strict.
Stefan_Lang 28-Jan-19 5:36am    
Richard is right. Don't try to mimic C++ in C. Just rewrite it as a standard for loop. Also, don't use macros - at least not at first. First make sure that the code works as intended without macros. When it does, and when there is a _very_ _good_ reason too introduce macros, you still shouldn't do it in Kernel code. The risk of messing something up really bad without realizing it, is just not worth whatever you think you're getting in return.
Member 14130865 28-Jan-19 16:18pm    
thanks to you all guys i looked at that array and i used the normal for loop and it worked :)

1 solution

It depends on very nature of the HashBuckets variable. What is it, exactly? You didn't provide any insight about.
I suggest you to NOT obfuscate C code behind macros. Wtite clean C code instead of trying to mimic the C++ counterpart.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900