5.4 XC32 C++ Compiler Options

The following are C++ compiler feature controls displayed in the MPLAB X IDE and VS Code project property dialogs, along with their corresponding driver options. When used, these options are applied at the first (code generation) stage of the compilation process.

Table 5-7. XC32 C++ Compiler C++ Specific Options Category
OptionDescriptionCommand Line
Generate run time type descriptor informationEnable generation of information about every class with virtual functions for use by the C++ runtime type identification features ('dynamic_cast' and 'typeid'). If you don't use those parts of the language, you can save some space by disabling this option. Note that exception handling uses the same information, but it will generate it as needed. The 'dynamic_cast' operator can still be used for casts that do not require runtime type information, i.e., casts to void * or to unambiguous base classes.-f[no-]rtti
Enable C++ exception handlingEnable exception handling. Generates extra code needed to propagate exceptions.-f[no-]exceptions
Check that the pointer returned by operator 'new' is non-nullCheck that the pointer returned by operator new is non-null before attempting to modify the storage allocated.-fcheck-new
Generate code to check for violation of exception specificationGenerate code to check for violation of exception specifications at runtime. Using this option may increase code size in production builds.-fenforce-eh-specs
Table 5-8. XC32 C++ Compiler General Options Category
OptionDescriptionCommand Line

Enable unaligned access

Enables (or disables) reading and writing of 16- and 32-bit values from addresses that are not 16- or 32-bit aligned. By default, unaligned access is disabled for all pre-ARMv6 and all ARMv6-M architectures and enabled for all other architectures. If unaligned access is not enabled then words in packed data structures are accessed one byte at a time.-m[no-]unaligned-access
Have symbols in production buildBuild for debugging in a production build image.-g
Isolate each function in a sectionPlace each function into its own section in the output file if the target supports arbitrary sections. The name of the function or the name of the data item determines the section's name in the output file. This option is useful when combined with the linker’s --gc-sections option to remove unreferenced functions.-ffunction-sections
Place data into its own sectionPlace each data item into its own section in the output file if the target supports arbitrary sections. The name of the function or the name of the data item determines the section's name in the output file. This option is useful when combined with the linker’s --gc-sections option to remove unreferenced variables.-fdata-sections
Enable toplevel reorderingAllow reordering of top-level functions, variables, and asm statements, such that they might not be output in the same order in which they appear in source files. When this feature is disabled, using the -fno-toplevel-reorder option, unreferenced static variables will not be removed. Use this options with optimization level 1 or greater.-f[no-]toplevel-reorder
Use indirect callsEnable full-range calls, which are typically required when calling a function in another memory region.-mlong-calls
Additional OptionsAdd options which do not have a dedicated control widget present in the properties dialog.
Table 5-9. XC32-G++ Optimization Category
OptionDescriptionCommand Line
Optimization LevelSelect an optimization level. Equivalent to -On option, where n is an option below:

0 - Do not optimize. The compiler’s goal is to reduce the cost of compilation and to make debugging produce the expected results.

1 - Optimize. Optimizing compilation takes somewhat longer, and a lot more host memory for a large function. The compiler tries to reduce code size and execution time.

2 - Optimize even more. The compiler performs nearly all supported optimizations that do not involve a space-speed trade-off.

3 - Optimize yet more favoring speed (superset of O2).

s - Optimize yet more favoring size (superset of O2).

-O0 -O1 -O2 -O3 -Os
Unroll loopsCheck to perform the optimization of loop unrolling. This is only done for loops whose number of iterations can be determined at compile time or run time.

Uncheck to not unroll loops.

-funroll-loops
Omit frame pointerCheck to not keep the Frame Pointer in a register for functions that don’t need one.

Uncheck to keep the Frame Pointer.

-fomit-frame-pointer
Pre-optimization instruction schedulingAttempts to reorder instructions to eliminate instruction stalls. Select "Default for optimization level" for this feature to be controlled purely by the -O level selection.-f[no-]schedule-insns
Post-optimization instruction schedulingAttempts to reorder instructions to eliminate instruction stalls. Select "Default for optimization level" for this feature to be controlled purely by the -O level selection.-f[no-]schedule-insns2
Use common tentative definitionsControls the placement of global variables defined without an initializer.-f[no-]common
Table 5-10. XC32-G++ Preprocessing and Messages Category
OptionDescriptionCommand Line
Preprocessor macrosProject-specific preprocessor macro defines passed via the compiler’s –D option.-Dmacro
Include directoriesSearch these directories for project-specific include files.

-I dir

Make warnings into errorsCheck to halt compilation based on warnings as well as errors.

Uncheck to halt compilation based on errors only.

-Werror
Additional warningsCheck to enable all warnings.

Uncheck to disable warnings.

-Wall
Enable Address-attribute warningEmit a warning for all uses of the address() attribute. This option is for engineering-support use only.-Waddress-attribute-use
Support-ansiCheck to issue all warnings demanded by strict ANSI C.

Uncheck to issue all warnings.

-ansi
Strict-ansi (VS Code only)Issue all the warnings demanded by strict ISO C and ISO C++; reject all programs that use forbidden extensions and some other programs that do not follow ISO C and ISO C++.-pedantic