A question about the programming language

Please accept my apologies for my ignorance on this. I have started learning C from a textbook and am considering following the handmadehero guide to help me learn C from a deep level (and fun!). On this link below people were saying that Casey is programming in C++ without the OOP part. Is that the same as straight C? And would that hurt my learning of C as I don't have any experience with C++ and hope not to mix the two at this stage as I would like to learn C++ later possibly. Thank you very much.

http://www.reddit.com/r/C_Program...on_regarding_writing_c_in_visual/

Edited by Steve on
!language...too bad that only works in the chat =X

It's ok no need to apologies!
Casey is using C with a touch of C++. For example he used some C++ such as operation override but he doesn't use the entire feature of C++ like classes or the Standard Template Library and such.
I don't think learning C will hurt and I do recommend the intro videos he did on youtube because most books don't teach people about the debugger and debugging is very important.
As COD3 said, handmade hero is mostly C (ANSI C if I'm correct not C99 or later).
You can find differences between ...fferent version of C on wikipedia.
No concept in handmade hero requires C++, meaning everything you will learn can be applied in C. The stream is more about teaching how to program a game that how to program in C. I recommend to watch the week 0: Intro to C videos to know if handmade hero is for you.

A few things in handmade hero will not work in pure C but can be converted to C with little changes:
- structure definition:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// C++ code:
struct StructName {
	int x;
	...
};

// C code:
typedef struct {
	int x;
	...
} StructName;

- Comments: in C you can only use /* and */ to write comment. In C++ you can used // to do a one line comment.
- Operator overloading: C++ allows you to redefine the behaviour of (most) operators. E.g. : you can change what + or - means between two types. Casey only use that for (math) vectors. It's not possible to do it in C, but it can be replaced by a function call.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// C++ code:
inline v2
operator+(v2 A, v2 B)
{
    v2 Result;

    Result.x = A.x + B.x;
    Result.y = A.y + B.y;

    return(Result);
}

v2 a = { 1.0f, 4.0f };
v2 b = { 2.0f, 3.0f };
v2 c = a + b;

// C code:
inline v2
v2Add(v2 A, v2 B)
{
    v2 Result;

    Result.x = A.x + B.x;
    Result.y = A.y + B.y;

    return(Result);
}

v2 a = { 1.0f, 4.0f };
v2 b = { 2.0f, 3.0f };
v2 c = v2Add( a, b );

- Function overloading: in C++ you can have function with the same name but different arguments types and/or order (the function signature: name of the function + arguments type and order. The return type is not part of the signature).
1
2
3
4
5
6
7
// C++ code:
float add( float a, float b ) { ... }
int add( int a, int b ) { ... }

// C code:
float addFloat( float a, float b ) { ... }
int addInt( int a, int b ) { ... }

- [Not sure]Function inlining might not work in C.
Thanks a lot for the detailed explanations. I will keep an eye out for those things you mentioned, thanks again.