Keil Logo

UNSIGNED_CHAR Compiler Directive

Abbreviation

UCH

Arguments

None.

Default

Variables of type char are signed.

µVision

Options — C166 — Treat 'char' as 'unsigned char'.

Description

The UNSIGNED_CHAR directive instructs the compiler to treat all variables declared with char as unsigned char variables.

Example
C166 SAMPLE.C UNSIGNED_CHAR

#pragma UCH

The following example:

 stmt lvl     source
    1         char  ch1;
    2         unsigned char uch2;   /* always unsigned */
    3         signed char sch3;     /* always signed   */
    4
    5         int i;
    6
    7         void test (void)  {
    8  1        if (ch1  > 0) i = ch1;
    9  1        if (uch2 > 0) i = uch2;
   10  1        if (sch3 > 0) i = sch3;
   11  1      }

demonstrates code generated using the SIGNED_CHAR directive:

Code Generated
Without UNSIGNED_CHAR
; FUNCTION uchar (BEGIN  RMASK = @0x0030)
                   ; SOURCE LINE # 7
                   ; SOURCE LINE # 8
0000 F3FA0200 R    MOVB      RL5,ch1
0004 49A0          CMPB      RL5,#00H
0006 BD03          JMPR      cc_SLE,?C0001
0008 D0A4          MOVBS     R4,RL5
000A F6F40000 R    MOV       i,R4
000E         ?C0001:
                   ; SOURCE LINE # 9
000E F3FA0300 R    MOVB      RL5,uch2
0012 49A0          CMPB      RL5,#00H
0014 FD03          JMPR      cc_ULE,?C0002
0016 C0A4          MOVBZ     R4,RL5
0018 F6F40000 R    MOV       i,R4
001C         ?C0002:
                   ; SOURCE LINE # 10
001C F3FA0400 R    MOVB      RL5,sch3
0020 49A0          CMPB      RL5,#00H
0022 BD03          JMPR      cc_SLE,?C0003
0024 D0A4          MOVBS     R4,RL5
0026 F6F40000 R    MOV       i,R4
002A         ?C0003:
                   ; SOURCE LINE # 11
002A CB00          RET
; FUNCTION uchar (END    RMASK = @0x0030)
CODE SIZE: 44 Bytes
Code Generated
With UNSIGNED_CHAR
; FUNCTION uchar (BEGIN  RMASK = @0x0030)
                   ; SOURCE LINE # 7
                   ; SOURCE LINE # 8
0000 F3FA0200 R    MOVB      RL5,ch1
0004 49A0          CMPB      RL5,#00H
0006 FD03          JMPR      cc_ULE,?C0001
0008 C0A4          MOVBZ     R4,RL5
000A F6F40000 R    MOV       i,R4
000E         ?C0001:
                   ; SOURCE LINE # 9
000E F3FA0300 R    MOVB      RL5,uch2
0012 49A0          CMPB      RL5,#00H
0014 FD03          JMPR      cc_ULE,?C0002
0016 C0A4          MOVBZ     R4,RL5
0018 F6F40000 R    MOV       i,R4
001C         ?C0002:
                   ; SOURCE LINE # 10
001C F3FA0400 R    MOVB      RL5,sch3
0020 49A0          CMPB      RL5,#00H
0022 BD03          JMPR      cc_SLE,?C0003
0024 D0A4          MOVBS     R4,RL5
0026 F6F40000 R    MOV       i,R4
002A         ?C0003:
                   ; SOURCE LINE # 11
002A CB00          RET
; FUNCTION uchar (END    RMASK = @0x0030)
CODE SIZE: 44 Bytes
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.