MPLAB XC32 C/C++ Compiler User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
MPLAB® XC32 C/C++ Compiler User’s Guide 2012-2016 Microchip Technology Inc. DS50001686J Note the following details of the code protection feature on Microchip devices: • Microchip products meet the specification contained in their particular Microchip Data Sheet. • Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions. • There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property. • Microchip is willing to work with the customer who is concerned about the integrity of their code. • Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as “unbreakable.” Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act. Information contained in this publication regarding device Trademarks applications and the like is provided only for your convenience The Microchip name and logo, the Microchip logo, AnyRate, and may be superseded by updates. It is your responsibility to dsPIC, FlashFlex, flexPWR, Heldo, JukeBlox, KEELOQ, ensure that your application meets with your specifications. KEELOQ logo, Kleer, LANCheck, LINK MD, MediaLB, MOST, MICROCHIP MAKES NO REPRESENTATIONS OR MOST logo, MPLAB, OptoLyzer, PIC, PICSTART, PIC32 logo, WARRANTIES OF ANY KIND WHETHER EXPRESS OR RightTouch, SpyNIC, SST, SST Logo, SuperFlash and UNI/O IMPLIED, WRITTEN OR ORAL, STATUTORY OR are registered trademarks of Microchip Technology OTHERWISE, RELATED TO THE INFORMATION, Incorporated in the U.S.A. and other countries. INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR ClockWorks, The Embedded Control Solutions Company, FITNESS FOR PURPOSE. Microchip disclaims all liability ETHERSYNCH, Hyper Speed Control, HyperLight Load, arising from this information and its use. Use of Microchip IntelliMOS, mTouch, Precision Edge, and QUIET-WIRE are devices in life support and/or safety applications is entirely at registered trademarks of Microchip Technology Incorporated the buyer’s risk, and the buyer agrees to defend, indemnify and in the U.S.A. hold harmless Microchip from any and all damages, claims, Analog-for-the-Digital Age, Any Capacitor, AnyIn, AnyOut, suits, or expenses resulting from such use. No licenses are BodyCom, chipKIT, chipKIT logo, CodeGuard, dsPICDEM, conveyed, implicitly or otherwise, under any Microchip dsPICDEM.net, Dynamic Average Matching, DAM, ECAN, intellectual property rights unless otherwise stated. EtherGREEN, In-Circuit Serial Programming, ICSP, Inter-Chip Connectivity, JitterBlocker, KleerNet, KleerNet logo, MiWi, motorBench, MPASM, MPF, MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach, Omniscient Code Generation, PICDEM, PICDEM.net, PICkit, PICtail, PureSilicon, RightTouch logo, REAL ICE, Ripple Blocker, Serial Quad I/O, SQI, SuperSwitcher, SuperSwitcher II, Total Endurance, TSHARC, USBCheck, VariSense, ViewSpan, WiperLock, Wireless DNA, and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. Microchip received ISO/TS-16949:2009 certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Silicon Storage Technology is a registered trademark of Tempe, Arizona; Gresham, Oregon and design centers in California Microchip Technology Inc. in other countries. and India. The Company’s quality system processes and procedures are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping GestIC is a registered trademarks of Microchip Technology devices, Serial EEPROMs, microperipherals, nonvolatile memory and Germany II GmbH & Co. KG, a subsidiary of Microchip analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified. Technology Inc., in other countries. All other trademarks mentioned herein are property of their respective companies. QUALITY MANAGEMENT SYSTEM © 2012-2016, Microchip Technology Incorporated, Printed in CERTIFIED BY DNV the U.S.A., All Rights Reserved. ISBN: 978-1-5224-0679-2 == ISO/TS 16949 == DS50001686J-page 2 2012-2016 Microchip Technology Inc. MPLAB® XC32 C/C++ COMPILER USER’S GUIDE Table of Contents Preface ........................................................................................................................... 9 Document Layout .................................................................................................. 9 Conventions Used ............................................................................................... 11 Recommended Reading...................................................................................... 12 Chapter 1. Compiler Overview 1.1 Introduction ................................................................................................... 15 1.2 Device Description ....................................................................................... 15 1.3 Compiler Description and Documentation .................................................... 15 1.4 Compiler and Other Development Tools ...................................................... 17 Chapter 2. Common C Interface 2.1 Introduction ................................................................................................... 19 2.2 Background – The Desire for Portable Code ............................................... 19 2.3 Using the CCI ............................................................................................... 22 2.4 ANSI Standard Refinement .......................................................................... 23 2.5 ANSI Standard Extensions ........................................................................... 31 2.6 Compiler Features ........................................................................................ 46 Chapter 3. How To’s 3.1 Introduction ................................................................................................... 47 3.2 Installing and Activating the Compiler .......................................................... 47 3.3 Invoking the Compiler ................................................................................... 49 3.4 Writing Source Code .................................................................................... 52 3.5 Getting My Application to Do What I Want ................................................... 62 3.6 Understanding the Compilation Process ...................................................... 66 3.7 Fixing Code That Does Not Work ................................................................. 73 Chapter 4. XC32 Toolchain and MPLAB X IDE 4.1 Introduction ................................................................................................... 75 4.2 MPLAB X IDE and Tools Installation ............................................................ 75 4.3 MPLAB X IDE Setup .................................................................................... 76 4.4 MPLAB X IDE Projects ................................................................................. 77 4.5 Project Setup ................................................................................................ 79 4.6 Project Example ........................................................................................... 90 Chapter 5. Compiler Command Line Driver 5.1 Introduction ................................................................................................... 93 5.2 Invoking the Compiler ................................................................................... 93 5.3 The C Compilation Sequence ...................................................................... 97 5.4 The C++ Compilation Sequence ................................................................ 100 2012-2016 Microchip Technology Inc. DS50001686J-page 3 MPLAB® XC32 C/C++ Compiler User’s Guide 5.5 Runtime Files ............................................................................................. 104 5.6 Start-Up and Initialization ........................................................................... 107 5.7 Compiler Output ......................................................................................... 109 5.8 Compiler Messages .................................................................................... 111 5.9 Driver Option Descriptions ......................................................................... 111 Chapter 6. ANSI C Standard Issues 6.1 Introduction ................................................................................................. 135 6.2 Divergence from the ANSI C Standard ...................................................... 135 6.3 Extensions to the ANSI C Standard ..........................................................