Home away from home ![Home away from home](https://www.amigans.net/uploads/rank3dbf8eb1a72e7.gif)
Joined: 2006/11/20 16:26 Last Login
: 8/23 19:45
From Norway
Group:
Registered Users
|
@NinjaCyborg
The thing is that C++ programs can use C libs, but C++ libs can’t be used by C programs. Anyway if you compile a amiga .library with C++, then AmigaOS does not find the symbols, ramlib does not support it.
As for the argument about structs & functions vs class & methods, is just a organizational & structural thing, sure things looks cleaner with classes, as you see where things belongs. As you are forced into a strict naming scheme.
Any way you can clean up C with few macros,
#define OON(sname,fname) sname ## _ ## fname(sname)
#define OOA(sname,fname,…) sname ## _ ## fname(sname, __VA_ARGS__)
carType *car;
color = OON(car,getColor);
OOA(car,setColor,0xFFFF0000);
I suggest organize things into .c files where one “object” is one .c file, so you have the functions for car in one place, car.c and data in car.h, if split things up keep source code clean, its not so hard to keep organized.
Anyway function points inside structs work more or less like virtual methods, only difference is that you must pass in struct pointer into as argument of the function pointer.
Another thing that is useful is
#ifdef __cplusplus #endif
So you can include methods for struct if header is included into a C++ program, the normal methods does not take up any space in struct. Anyway, you need function outside of struct, for normal C programs, so it does not really solve it. in the end is code style thing. The extra work to support the C++ style become boilerplate code.
Edited by LiveForIt on 2021/3/16 16:58:17 Edited by LiveForIt on 2021/3/16 17:02:26 Edited by LiveForIt on 2021/3/16 17:11:02 Edited by LiveForIt on 2021/3/16 17:16:44 Edited by LiveForIt on 2021/3/16 17:18:10 Edited by LiveForIt on 2021/3/16 17:34:33 Edited by LiveForIt on 2021/3/16 17:35:41 Edited by LiveForIt on 2021/3/16 17:37:29 Edited by LiveForIt on 2021/3/16 17:53:59 Edited by LiveForIt on 2021/3/16 17:59:32 Edited by LiveForIt on 2021/3/16 18:22:17 Edited by LiveForIt on 2021/3/16 18:28:38
|