Simple C Question

So I guess this is kinda a “lazy” question I suppose but its one of those concepts I find take forever to fully appreciate. I’ve been studying blenders source code for a little while now and I can read C and I understand how it works and such to an extent. But I’m coming from python and mel and this is obviously quite different.

My question is how does blender act on object data(not sure of a better way to put it), I mean from my understanding *ob points to the active object. And the selected object would be a different pointer? And you must include context.h in order to the get object or a DNA type or… For me I need to know why something works not just how.

I try to read these files and I just always feel like something is missing, but maybe I’m looking at it wrong? I guess at some point its not calling data but “initializing” it. Although I don’t think that makes sense.

My biggest issue is how does the C code interact with the active scene? Say I wanted to make a modifier. I suppose I would want to create a struct that contained Object *ob and an int that made the modifier active. So when I applied the modifier I had the object I wanted selected so *ob would point to that object. But then if I selected another object it would still point to the first object? If that’s true then *ob would point to any object that was active when basically any piece of code of called, or is Object temporary and it is passed on to a local pointer?

So I guess that’s more rambling then a clear question, but I can spend forever being hung up on this concept, it would be awesome is someone could help put it in clearer terms.

Thank you

I suppose the active object is just stored in a global variable. If they have a flag to mark active an object (having such flags in each object) and then they have a function to look for the flag on and decide that is the active object… then it would be just stupid code.

So I suppose they have a variable like:

uint g_ActiveObject;

And you read it and know what the active object is. You write it and you are telling the rest of blender what the active object now is.

You read the above variable name I wrote and you know, because the “g_” that it is a global variable, and because the upper and lowercase you understand easily where each word starts. They are following other convention (the above one is called Camel or Polish convention). So probably in blender that variable will be something like:

uint object_active;

there is a utility function:

struct Object *CTX_data_active_object(const bContext *C)
    return ctx_data_pointer_get(C, "active_object");

which is basically doing:

    if (CTX_py_dict_get(C)) {
        return BPY_context_member_get(C, member, result);

Not sure though where the context is actually created, might be tightly bound with python.

Thanks you both for the answers. I had more questions but I kept needing to change them every five seconds so I gave up. I think I have some idea of how this works now, maybe.

Can anyone tell me how to get the target objects vertex coordinates? I’m working on a modifier and I need all the coordinates of the target objects verts. Do i get it from Object structure or DerivedMesh [EDIT: is derived mesh a data type, I mean I think that sounds dumb but is it like a struct type thing I can declare and use for vertex cos??]
or make a custom data type, or am I really really far off??