Handmade Hero»Forums»Code
Phillip
2 posts
Follow along using pure C?
Hey guys, since Casey is using mostly C with a little C++, I was wondering how possible it would be to follow along using just C with a C compiler.

I know how to deal with the struct declarations, bools, and function overloading, but I'm not sure how big a problem operator overloading will be.

I'm assuming that it will be used to do math operations(+, -, *, /) on structs, if that's the case then I'm guessing I could just create functions to perform the math and use

1
StructMathFunction(StructA, StructB, StructC);


instead of

1
StructC = StructA + StructB;


Or is it going to be used for a different purpose that would be more difficult to rewrite in C?
Benjamin Kloster
48 posts
Follow along using pure C?
Operator overloading is really just syntactic sugar. The compiler replaces all applications of the operator with its corresponding function call. So yes, you can just define functions like Vec2Add and friends and call those instead.
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Follow along using pure C?
Yeah, I actually did all of Granny 3D without doing operator overloading for math, it was all BLAS-style (http://www.netlib.org/blas/) where you just have a function for every type of common math operation. It works, it's just much harder to read. There's no performance penalty (if anything, there might be a performance improvement, depending on how you structure your functions!)

- Casey