The 25 days of C++mas - December 13 - Migrating C++Builder Code to 64-bits
On Wednesday morning, December 12, at the CodeRage 7 C++ Conference, Bruneau Babet (Embarcadero C++ R&D Engineer) presented a session showing developers how to migrate their C++Builder XE3 32-bit applications to 64-bit Windows. Bruneau's session covered some of the differences between the Embacadero Win32 and Win64 C++ compilers, comparing keywords, macros, extensions and standards conformance for both compilers. During the session, John Thomas, Embarcadero's Director of Product Management for Developer Tools, guided the conversation to discuss the new compiler, the use of Clang, LLVM and strategies for porting existing C++ Projects and writing new code in a way that works for both Platforms. Here are a few tidbits taken from the slides used in Bruneau's presentation. The replay of the session will appear as "watch" and "download" links on the conference session entry sometime next week.
clang and llvm
The clang compiler front end has a modular library-based architecture. It is a real-world, production quality compiler with conformance with C/C++/Objective-C and their variants.
C++Builder Win64
The new C++Builder Win64 compiler is created by combining clang and the Embarcadero/Borland extensions. With C++Builder Win64, the Embarcadero C++ team created the first Windows 64-bit back end.
C++ Compiler Extensions to support Windows and Delphi Language
Delphi Language compatibility extensions – required to allow C++Builder developers to use Delphi reusable GUI components, RTL functions and other language features use of Delphi components (Properties, Methods, Events) and other Delphi language features including closures and enhanced RTTI:
Win64 porting items to pay attention to
Watch/Download the C++Builder 64-bit Compiler Preview Video
Additional details about the 64-bit C++Builder compiler are available in the preview video. Watch the C++ 64-bit compiler preview video on YouTube at http://www.youtube.com/watch?v=PwwMpBUoR6Y. You can also download the MP4 video file at http://cc.embarcadero.com/item/29197. The preview video is 9 minutes long.
Try the C++Builder 64-bit compiler
The C++Builder XE3 and RAD Studio XE3 free trial downloads have been updated to include the new C++Builder 64-bit compiler. Trial downloads are available at https://downloads.embarcadero.com/free/c_builder
Happy C++mas!
During the first 25 days of December leading up to Christmas, I will blog about the release of the C++Builder 64-bit compiler for Microsoft Windows and C++Builder XE3 support for building VCL and FireMonkey 2 applications.
clang and llvm
The clang compiler front end has a modular library-based architecture. It is a real-world, production quality compiler with conformance with C/C++/Objective-C and their variants.
- http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Clang-Defending-C-from-Murphy-s-Million-Monkeys
- http://devimages.apple.com/llvm/videos/ExtendingClang.m4v
- http://llvm.org/devmtg/2011-11/Gregor_ExtendingClang.pdf
- Great optimizations (http://llvm.org/docs/Passes.html)
- Online Demo ( http://llvm.org/demo/)
C++Builder Win64
The new C++Builder Win64 compiler is created by combining clang and the Embarcadero/Borland extensions. With C++Builder Win64, the Embarcadero C++ team created the first Windows 64-bit back end.
- bcc64 = clang + Embarcadero/Borland Extensions
- -fborland-extensions compiler option
C++ Compiler Extensions to support Windows and Delphi Language
- __uuidof(expression) – returns the GUID associated with the expression passed to the function - http://docwiki.embarcadero.com/RADStudio/XE3/en/Uuidof
- __try – exception handling can be used in C and C++ programs. Also provided in the Delphi language - http://docwiki.embarcadero.com/RADStudio/XE3/en/Try_(C)
- __except (expression) compound-statement – exception actions based on an expression. Also provided in the Delphi language - http://docwiki.embarcadero.com/RADStudio/XE3/en/Except
- __finally {compound statement} – where you can specify actions that will be executed regardless of the handling of specific
- __declspec(<decl-modifier>) - __declspec keyword to indicate the storage class attributes for a variable or function. There is a list of modifiers including some needed for Windows and some neededfor Delphi - http://docwiki.embarcadero.com/RADStudio/XE3/en/Declspec
- __declspec(selectany) - used in initializing global data defined by headers, when the same header appears in more than one source file. http://docwiki.embarcadero.com/RADStudio/XE3/en/Declspec%28selectany%29
- __declspec(uuid(“”)) - The compiler attaches a GUID to a class or structure declared or defined - http://docwiki.embarcadero.com/RADStudio/XE3/en/Declspec(uuid(%22ComObjectGUID%22))
- __declspec(dllexport) - The dllexport storage-class attribute is used for Microsoft C and C++ and Delphi language compatibility. http://docwiki.embarcadero.com/RADStudio/XE3/en/Declspec(dllexport)
- __declspec(dllimport) - The dllimport storage-class attribute is used for Microsoft C and C++ and Delphi language compatibility. http://docwiki.embarcadero.com/RADStudio/XE3/en/Declspec(dllimport)
- --declspec(delphirtti) - The delphirtti storage-class attribute is used to allow C/C++ code to request RTTI on Delphi objects. http://docwiki.embarcadero.com/RADStudio/XE3/en/Declspec(delphirtti)
Delphi Language compatibility extensions – required to allow C++Builder developers to use Delphi reusable GUI components, RTL functions and other language features use of Delphi components (Properties, Methods, Events) and other Delphi language features including closures and enhanced RTTI:
- __classid - The __classid operator was added to support the VCL and FireMonkey (FMX) frameworks. You can use it to obtain the metaclass of a TObject-based class (a Delphi-style class). http://docwiki.embarcadero.com/RADStudio/XE3/en/C%2B%2B_Keyword_Extensions#_classid
- __classmethod - The
__classmethod
keyword was added to declare class methods in C++. A class method is similar to a static method, except that it has an additional (hidden) parameter: the metaclass of the class where the method is defined. Delphi language has class methods. http://docwiki.embarcadero.com/RADStudio/XE3/en/Classmethod and http://docwiki.embarcadero.com/RADStudio/XE3/en/Class_Methods - __closure - There are two kinds of function pointers that can be used in C++. The first is a simple pointer to a global function (not a member of a class). When dealing with class member functions, a simple pointer to a method is not sufficient to make a call. Instead, two pointers are required: one for the originating object and the second for the method address. All VCL and FireMonkey (FMX) component events are declared as closures, in order to allow methods of a class to be called when the event is fired. The following code is an excerpt from the Classes.hpp header, showing the declaration of the TNotifyEvent, used in many events in VCL and FMX (e.g. OnClick). http://docwiki.embarcadero.com/RADStudio/XE3/en/Closure and http://docwiki.embarcadero.com/RADStudio/XE3/en/C%2B%2B_Keyword_Extensions#_closure
- __delphirtti(TYPE) -
__delphirtti(TYPE)
returns the Delphi type information.__delphirtti(TYPE)
is the C++ counterpart of the TypeInfo function available in Delphi. http://docwiki.embarcadero.com/RADStudio/XE3/en/Delphirtti, http://docwiki.embarcadero.com/Libraries/XE3/en/System.TypInfo.TTypeInfo and http://docwiki.embarcadero.com/Libraries/XE3/en/System.TypeInfo - __property - The __property keyword was added to support the VCL and FireMonkey (FMX) class properties. The __property keyword declares an attribute of a class. Properties appear to the programmer just like any other attribute (field) of a class. However, like its Object Pascal counterpart, C++ Builder’s __property keyword adds significantly more functionality beyond just examining and changing the value of the attribute. Since property attributes completely control access to the property, there are no restrictions on how you implement the property within the class itself. http://docwiki.embarcadero.com/RADStudio/XE3/en/Property and http://docwiki.embarcadero.com/RADStudio/XE3/en/C%2B%2B_Keyword_Extensions#_property
- __published – The __published keyword was added to support the VCL and FireMonkey (FMX) frameworks. This public member access specifier is similar to the public specifier, but __published has compiler-generated RTTI (run-time type identification) attached. This means the __published properties appear in the IDE’s Object Inspector View at design time. The __published keyword specifies that properties in that section are displayed in the Object Inspector, if the class is on the Component palette. Only classes derived from TObject can have __published sections. The visibility rules for published members are identical to those of public members. The only difference between published and public members is that Object Pascal-style run-time type information (RTTI) is generated for data members and properties declared in a __published section. RTTI enables an application to dynamically query the data members, member functions, and properties of an otherwise unknown class type. http://docwiki.embarcadero.com/RADStudio/XE3/en/Published.
Win64 porting items to pay attention to
- sizeof(ptr) != sizeof(int) - Use size_t for memory size
- _WIN32 is defined - Check for _WIN64 instead
- Bit shifting - Watch for 32-bit constants
Watch/Download the C++Builder 64-bit Compiler Preview Video
Additional details about the 64-bit C++Builder compiler are available in the preview video. Watch the C++ 64-bit compiler preview video on YouTube at http://www.youtube.com/watch?v=PwwMpBUoR6Y. You can also download the MP4 video file at http://cc.embarcadero.com/item/29197. The preview video is 9 minutes long.
Try the C++Builder 64-bit compiler
The C++Builder XE3 and RAD Studio XE3 free trial downloads have been updated to include the new C++Builder 64-bit compiler. Trial downloads are available at https://downloads.embarcadero.com/free/c_builder
Happy C++mas!
During the first 25 days of December leading up to Christmas, I will blog about the release of the C++Builder 64-bit compiler for Microsoft Windows and C++Builder XE3 support for building VCL and FireMonkey 2 applications.
Tags:
64-bit
C++
C++11
C++2011
C++Builder
FireMonkey
GUI
Languages
Programming
RAD Studio
VCL
Windows


David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.
Are these extensions to be contributed back to the LLVM/clang projects?