MPLAB C30 C Compiler User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
MPLAB® C30 C COMPILER USER’S GUIDE © 2007 Microchip Technology Inc. DS51284F 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, Accuron, and may be superseded by updates. It is your responsibility to dsPIC, KEELOQ, KEELOQ logo, microID, MPLAB, PIC, ensure that your application meets with your specifications. PICmicro, PICSTART, PRO MATE, PowerSmart, rfPIC, and MICROCHIP MAKES NO REPRESENTATIONS OR SmartShunt are registered trademarks of Microchip WARRANTIES OF ANY KIND WHETHER EXPRESS OR Technology Incorporated in the U.S.A. and other countries. IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, AmpLab, FilterLab, Linear Active Thermistor, Migratable INCLUDING BUT NOT LIMITED TO ITS CONDITION, Memory, MXDEV, MXLAB, PS logo, SEEVAL, SmartSensor QUALITY, PERFORMANCE, MERCHANTABILITY OR and The Embedded Control Solutions Company are FITNESS FOR PURPOSE. Microchip disclaims all liability registered trademarks of Microchip Technology Incorporated arising from this information and its use. Use of Microchip in the U.S.A. devices in life support and/or safety applications is entirely at Analog-for-the-Digital Age, Application Maestro, CodeGuard, the buyer’s risk, and the buyer agrees to defend, indemnify and dsPICDEM, dsPICDEM.net, dsPICworks, ECAN, hold harmless Microchip from any and all damages, claims, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB, suits, or expenses resulting from such use. No licenses are In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, conveyed, implicitly or otherwise, under any Microchip MPASM, MPLAB Certified logo, MPLIB, MPLINK, PICkit, intellectual property rights. PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, rfPICDEM, Select Mode, Smart Serial, SmartTel, Total Endurance, UNI/O, WiperLock 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. All other trademarks mentioned herein are property of their respective companies. © 2007, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved. Printed on recycled paper. Microchip received ISO/TS-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona, Gresham, Oregon and Mountain View, California. The Company’s quality system processes and procedures are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified. DS51284F-page ii © 2007 Microchip Technology Inc. MPLAB® C30 USER’S GUIDE Table of Contents Preface ........................................................................................................................... 1 Chapter 1. Compiler Overview 1.1 Introduction ..................................................................................................... 7 1.2 Highlights ........................................................................................................ 7 1.3 MPLAB C30 Description ................................................................................. 7 1.4 MPLAB C30 and Other Development Tools ................................................... 7 1.5 MPLAB C30 Feature Set ................................................................................ 9 Chapter 2. Differences Between MPLAB C30 and ANSI C 2.1 Introduction ................................................................................................... 11 2.2 Highlights ...................................................................................................... 11 2.3 Keyword Differences .................................................................................... 11 2.4 Statement Differences .................................................................................. 30 2.5 Expression Differences ................................................................................ 31 Chapter 3. Using MPLAB C30 C Compiler 3.1 Introduction ................................................................................................... 33 3.2 Highlights ...................................................................................................... 33 3.3 Overview ...................................................................................................... 33 3.4 File Naming Conventions ............................................................................. 34 3.5 Options ......................................................................................................... 34 3.6 Environment Variables ................................................................................. 59 3.7 Predefined Constants ................................................................................... 60 3.8 Compiling a Single File on the Command Line ............................................ 60 3.9 Compiling Multiple Files on the Command Line ........................................... 61 © 2007 Microchip Technology Inc. DS51284F-page iii MPLAB® C30 User’s Guide Chapter 4. MPLAB C30 C Compiler Runtime Environment 4.1 Introduction ................................................................................................... 63 4.2 Highlights ...................................................................................................... 63 4.3 Address Spaces ........................................................................................... 63 4.4 Code and Data Sections .............................................................................. 65 4.5 Startup and Initialization ............................................................................... 67 4.6 Memory Spaces ........................................................................................... 68 4.7 Memory Models ............................................................................................ 69 4.8 Locating Code and Data ............................................................................... 71 4.9 Software Stack ............................................................................................. 72 4.10 The C Stack Usage .................................................................................... 73 4.11 The C Heap Usage ..................................................................................... 75 4.12 Function Call Conventions ......................................................................... 76 4.13 Register Conventions ................................................................................. 78 4.14 Bit Reversed and Modulo Addressing ........................................................ 79 4.15 Program Space Visibility (PSV) Usage ...................................................... 79 Chapter 5. Data Types 5.1 Introduction ................................................................................................... 81 5.2 Highlights ...................................................................................................... 81 5.3 Data Representation .................................................................................... 81 5.4 Integer .......................................................................................................... 81 5.5 Floating Point ............................................................................................... 82 5.6 Pointers ........................................................................................................ 82 Chapter 6. Device Support Files 6.1 Introduction ................................................................................................... 83 6.2 Highlights ...................................................................................................... 83 6.3 Processor Header Files ...............................................................................