this post was submitted on 18 Jun 2023
12 points (100.0% liked)
Programming
13386 readers
2 users here now
All things programming and coding related. Subcommunity of Technology.
This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
There are a many approaches to implementing OOP in C. Since C doesn’t give you any language constructs to implement this out of the box, it’s up to you to do it in a consistent and understandable manner. Since there is no definite way to do it, let me just give you an example of how I would translate a Python file, and you can decide how you implement it from there:
I would split the C code for this into header and source files:
(header.h)
(source.c)
Modules and namespaces can be modeled using folders and prefixing your structs and functions.
This. Although I would argue it is a bad practice inherit from a class, only from an interface. GObject is your friend.