C++Builder: classic compiler vs clang
Pro et contra
I use C++Builder 10.1 (Berlin) that proposes both 'classic' bcc32 compiler and new clang bcc32c. Whether do you rather to use classic compiler or to switch to clang? The answer is not quite simple.
The advantages of new clang compiler:
- more of C++11 language and standard library support;
- both 32-bits and 64-bits compilers;
- the BOOST library is newer (1.39 for 'classic' vs 1.55 for clang);
- the syntax and semantic checking is stricter;
- generated code is better (I can confirm on the small test, see below).
Good reasons, aren't they? Yes, they are but be aware of drawbacks:
- Code Guard tool doesn't work with clang compiled executables (my bug report). So you cannot easily detect memory leaks and other issues;
- the clang compiler is slower, really slower. Running with my projects I get the slowdown 4-5 times (up to 10 in extreme case);
- Code Insight freeze the IDE for many seconds when typing the code. You would better to deactivate some options like "Auto parenthesis", "Tooltip symbol" or "Hints" to work normally;
- some compiler messages like
Warning: public '__tpdsc__ void' in module 'AAA' clashes with prior module 'BBB'
seem to be wrong.
For example, one static library project (11450 lines) using STL and Delphi library headers:
- clang bcc32c - 165 sec (02:45)
- 'classic' bcc32 - 44 sec (00:44)
These drawbacks have been crucial for me so after two weeks of clang programming I switched back to the 'classic' compiler.
Generated code quality
My very simple quality test of compiler generated code is "Happy tickets", we will take the C code from here.
Command line options to compile are:
bcc32.exe -O2 -o tickets1.exe tickets.cpp
bcc32c.exe -O2 -o tickets2.exe tickets.cpp
Results
On my PC (Intel i5-3470 \@3.2 GHz 4 core, RAM 16 GB)
Parameter | 'classic' bcc32 executable | clang bcc32c executable |
---|---|---|
Size, bytes | 63 488 | 62 976 |
Average time for 10 runs, msec | 203 | 47 |
As you can see, clang compiler generated code is really faster on the small test that needs some algorithmic optimization.
Conclusions
I'd like to recommend to stay with the 'classic' in main development but to support your sources compatible with the clang compiler at the same time. This combined approach lets you to develop faster and to use standard Embarcadero documented tools but also to compile release or other than Win32 binaries with clang.
blog comments powered by Disqus