0 votes

According to Wikipedia, Godot is written in C and C++. Why can't Godot just be written in C++? What advantages does C have over C++?

asked Jul 20, 2018 in Engine by Joe0239 (176 points)

2 Answers

0 votes

I don't think it's about the choice but rather a byproduct and accumulation of using other third-party libraries that are written in C language like zlib.

The other reason might be simply because the C language provides a lower level access that allows to optimize critical parts of the engine.

Another reason might arise from the fact that writing in C language gives opportunity to support more hardware platforms.

answered Jul 20, 2018 by Xrayez (1,106 points)

I thought C++ can be just as low level as C?

Both C and C++ are considered low-level languages. The need for creating C was arisen from making assembler more human-readable. One can clearly see how C and C++ differ from each other when it comes down to string manipulations, for instance:

char str1[16];
char str2[16];
strcpy(str1, str2);

vs

String str1, str2;
str1 = str2;

With the first example you need to make sure that str1's size is long enough to contain str2, in C++ you can just use String class that does that for you ensuring you don't do any stupid mistakes that would result in memory overflows (in cost of some decrease in performance). I think it boils down to how abstract these operations could go and how languages manage memory in general.

The distinction between C and C++ might be blurry because you can always you C functions while still benefiting from using C++ features like classes. This is another reason why the code statistics might show mixed usage result.

0 votes

Many libraries expose themselves via C API because C++ ABI is not stable

Godot needs C code to interact with libraries.

It's also the reason why GDNative is ship with a C ABI as its base.

answered Jul 20, 2018 by hungrymonkey (419 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.