How to use Main *bmain?

OK, trying to do something like this

for(Object *ob = bmain->objects.first; ob ; ob = ob->id.next)

from looking at code it looks like I do something like this?

bContext *C;

Main *bmain = CTX_data_main(C);

for(Object *ob = bmain->objects.first; ob ; ob = ob->id.next){

but it keep saying uninitialized local variable 'C' used

How do I get proper context to use Main *bmain?

I can do like collectionObject *cob; and it doesn’t give me the uninitialized local variable.

The local variable C is indeed uninitialized. Meaning when you declare it there with bContext *C, it’s only a pointer to some arbitrary place in memory and it won’t be possible to retrieve any data from it.

This is a great thing really, and it’s why static variables are something to avoid usually. You’ll only be able to use the context where Blender’s architecture has made it possible (most likely for good reason). In other words, only where the variable C or bmain already exist.

OK, is it possible to loop through mesh objects from modifiers? The only way I saw looking through the code was for(Object *ob = bmain->objects.first; ob ; ob = ob->id.next) which needs Main, LOL.

Modifiers should not loop through all objects in the scene, only objects specified to it by the user. Dependencies on all used objects should also be added in updateDepsgraph.