Holtek C and ANSI C Feature Comparison User s Guide July 2009 Copyright 2009 by HOLTEK SEMICONDUCTOR INC. All rights reserved. Printed in Taiwan. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form by any means, electronic, mechanical photocopying, recording, or otherwise without the prior written permission of HOLTEK SEMICONDUCTOR INC.
NOTICE The information appearing in this User s Guide is believed to be accurate at the time of publication. However, Holtek assumes no responsibility arising from the use of the specifications described. The applications mentioned herein are used solely for the purpose of illustration and Holtek makes no warranty or representation that such applications will be suitable without further modification, nor recommends the use of its products for application that may present a risk to human life due to malfunction or otherwise. Holtek reserves the right to alter its products without prior notification. For the most up-to-date information, please visit our web site at http://www.holtek.com.tw.
Contents Contents Data Types and Sizes...1 Arrays...2 Reserved Keywords...2 Operators...4 Preprocessor Directive #pragma...5 Constant Variables...5 Predefined Headers...6 Main Function...6 Interrupt Function...7 Built-in Functions...7 Other Functions...8
Software version Holtek C Enhanced Holtek C Holtek (R) Cross C Compiler Version V2.02 MRSC Holtek (R) Cross C Compiler Version V2.36 E-MRSC (2008/5/22) Note Y indicates a Yes and N indicates a No in the following sections of this DOC. Data Types and Sizes Holtek C Enhanced Holtek C ANSI C Data Type Size (bits) Size (bits) Size (bits) Bit 1 1 N Char 8 8 8 signed char 8 8 8 Unsigned char 8 8 8 Short 8 16 16 Unsigned short 8 16 16 Int 8 16 16 unsigned int 8 16 16 Long 16 32 32 unsigned long 16 32 32 Void 0 0 0 Float N 32 32 Double N 32 64 Long double N N 128 Float and double are both 32-bit format of the IEEE 754 spec. 1
Arrays Holtek C Enhanced Holtek C ANSI C Dimension (Max Size) (Max Size) (Max Size) 1-Dimensional Y (256) Y (256) Y 2-Dimensional N Y (256) Y 3 or above Dimensional N N Y Array of pointers N Y (256) Y Function Array N Y (256) Y Reserved Keywords Keywords Holtek C Enhanced Holtek C ANSI C auto break bit Y Y N Case char const constant N Y N continue default do double N Y Y else enum extern float N Y Y for goto if int 2
Keywords Holtek C Enhanced Holtek C ANSI C auto long register N Y Y return short signed sizeof static struct switch typedef union unsigned void volatile while 3
Operators Operators Holtek C Enhanced Holtek C ANSI C Arithmetic operators (+-*/%) Relational operators (> < == >= <=!=) Logical operators (! && ) Bitwise operators (<< >> ~ ^ &) Assignment operators (= += -= *= /= %= >>= <<= &= ^= =) Conditional operators (? :) Comma operator (,) Reference operator (* &) Size-of operator (sizeof) Cast operator ((Tpe)) Member operators (. ->) Subscription operator ([ ]) Function call operator (( )) Increment operator (++) Decrement operator (--) Unary minus operator (-) Unary plus operator (+) Y Y N Operator to specify RAM variable address (@) Y Y N 4
Preprocessor Directive #pragma Syntax: #pragma keyword [option] Some options may exist for some keywords. Keyword Holtek C Enhanced Holtek C ANSI C Option bp_free N Y N N Bp_nofree N Y N N function N Y N Y nobp N Y N N nolocal N Y N Y nomp0 N Y N N nomp1 N Y N N rambank0 norambank Y Y N N Rombank0 norombank N Y N N rombank N Y N Y vector Y Y N Y novectornest N Y N N Constant Variables Constant Variable Holtek C Enhanced Holtek C ANSI C Adaptive data type any any any Attribute public/relocatable private public/private/internal Can be invoked by other files N Y (Add extern directive before const) Y (Add extern directive before const) Must be declared as global variable Must be initialized when declared Must specify the dimension for constant array Constant strings must be used in the C file with main function Y Y N 5
Predefined Headers Header File Holtek C Enhanced Holtek C ANSI C HTxxxxxx.h Y Y N assert.h N N Y ctype.h N N Y errno.h N N Y float.h N N Y limits.h N N Y locale.h N N Y math..h N N Y setjmp.h N N Y signal.h N N Y stdarg.h N N Y stddef.h N N Y stdio.h N N Y stdlib.h N N Y string.h N N Y time.h N N Y Main Function Rule Holtek C Enhanced Holtek C ANSI C Number 1 1 1 Return type void void void Argument No No 2 6
Interrupt Function Rule Holtek C Enhanced Holtek C ANSI C For setup interrupt vector Y Y Number multiple multiple Return type void void Argument N N Reentrant allowed N Y (1) No interrupt function for ANSI C Call ISR explicitly in programs N N Call functions in ISR N (2) N (2) (1) It is only for these kinds of MCU that nested interrupts are allowed. It should be noted that the same interrupt cannot be nested at all times. (2) The user defined function written in C should not be called within the ISR. It is safe to use system calls. If it is desired to call a function within the ISR, then it should be written in assembly. It is safe to call the built-in function within the ISR. Built-in Functions Operators Holtek C (Argument) Enhanced Holtek C (Argument) ANSI C _clrwdt() Y Y N _clrwdt1() Y Y N _clrwdt2() Y Y N _halt() Y Y N _nop() Y Y N _rr(int *) Y(int *) Y(char *p) N _rrc(int *) Y(int *) N _lrr(long *) Y(long *) Y(int *pl) N _lrrc(long *) Y(long *) N _rl(int *) Y(int *) Y(char *p) N _rlc(int *) Y(int *) N _lrl(long *) Y(long *) Y(int *pl) N _lrlc(long *) Y(long *) N _swap(int *) Y(int *) Y(char *p) N 7
Operators Holtek C (Argument) Enhanced Holtek C (Argument) ANSI C _delay(unsigned long tick) Y(tick<=65535) Y(tick<=263690) N Mathematical functions N N Y Character and string functions N N Y Standard Input/output function N N Y Dunamic memory allocation functions N N Y The standard C libraries (math, string, stdio, stdlib ) are not supported by the Holtek C compilers. Other Functions Operators Holtek C Enhanced Holtek C ANSI C In line assembly Y Y N Static variable No local static variable No local static variable A local static variable is allowed Constant Support binary constant value Support binary constant value NOT Support binary constant value function No reentrant and recursive allowed No reentrant and recursive allowed Support reentrant and recursive Pointer Not for constant and bit variable Not for constant and bit variable Not for constant (no bit variable) Initialization No for global variables. Yes for local variables. Necessary for constant variables. No for global variables. Yes for local variables. Necessary for constant variables. Yes for both global and local variables. Necessary for constant variables. stack Limited level (1) Limited level (1) Unlimited level (1) For HOLTEK C/Enhanced HOLTEK C, the stack level limit during function calls in the program must be considered. 8
The stack level consumption of some operators and functions are as follows: Operator/Function Holtek C Enhanced Holtek C ANSI C main() 0 _rl(int */ char *p); 0 _clrwdt() 0 _rlc(int *); 0 _clrwdt1() 0 _lrl(long */ int *pl); 0 _clrwdt2() 0 _lrlc(long *); 0 _halt() 0 _delay(unsigned long) 1 _nop() 0 * 1 _rr(int */ char *p); 0 / 1 _rrc(int *); 0 % 1 _lrr(long */ int *pl); 0 Constant array 1 _lrrc(long *); 0 9
Holtek Semiconductor Inc. (Headquarters) No.3, Creation Rd. II, Science Park, Hsinchu, Taiwan Tel: 886-3-563-1999 Fax: 886-3-563-1189 http://www.holtek.com.tw Holtek Semiconductor Inc. (Taipei Sales Office) 4F-2, No. 3-2, YuanQu St., Nankang Software Park, Taipei 115, Taiwan Tel: 886-2-2655-7070 Fax: 886-2-2655-7373 Fax: 886-2-2655-7383 (International sales hotline) Holtek Semiconductor Inc. (Shenzhen Sales Office) 5F, Unit A, Productivity Building, No.5 Gaoxin M 2nd Road, Nanshan District, Shenzhen, China 518057 Tel: 86-755-8616-9908, 86-755-8616-9308 Fax: 86-755-8616-9722 Holtek Semiconductor (USA), Inc. (North America Sales Office) 46729 Fremont Blvd., Fremont, CA 94538 Tel: 1-510-252-9880 Fax: 1-510-252-9885 http://www.holtek.com Copyright 2009 by HOLTEK SEMICONDUCTOR INC. The information appearing in this User s Guide is believed to be accurate at the time of publication. However, Holtek assumes no responsibility arising from the use of the specifications described. The applications mentioned herein are used solely for the purpose of illustration and Holtek makes no warranty or representation that such applications will be suitable without further modification, nor recommends the use of its products for application that may present a risk to human life due to malfunction or otherwise. Holtek s products are not authorized for use as critical components in life support devices or systems. Holtek reserves the right to alter its products without prior notification. For the most up-to-date information, please visit our web site at http://www.holtek.com.tw. 10