How to properly write a struct [duplicate]

Solution 1:

// this is called function signature or declaration, 
// and typically it's what's found in
// header files, this is all that's needed to properly generate the code
// to call this function.

void Point_print(const struct screen* self); // <-- what is the purpose of having this function?

Now that it's declared you can use it:

int main(int argc, const char * argv[]) {
    
    struct screen aScreen;
    aScreen.x = 1.0;
    aScreen.y = 2.0;
    
    Point_print(&aScreen); // <--- it's the use here
    return 0;
}

This is the function body or implementation:

void Point_print(const struct screen * self){ // <-- this function is doing the work?
    printf("x:%f, y:%f",(*self).x,(*self).y);
}

When the linking step occurs it resolves the "link" between the "calling points" and where the actual body of the function.

One way to experience is to comment out the function body part completely and try compiling the file with main in it, it will compile correctly, however will spew out linking error.

Solution 2:

Compilers read code from top to bottom. Hence if there was no declaration of Point_print above main, the compiler would not know what arguments and return values to expect from Point_print by the time it reads the first call to it.

Here's a more detailed article about function declarations:

https://www.programiz.com/c-programming/c-user-defined-functions