Keil Logo

SIGNED_CHAR Compiler Directive

Abbreviation

SCH

Arguments

None.

Default

Variables of type char are unsigned.

µVision

Options — CA — Treat plain char as 'unsigned char'.

Description

The SIGNED_CHAR directive instructs the compiler to treat all variables declared with char as signed char variables.

Example
CA SAMPLE.C SIGNED_CHAR

#pragma SCH

The following example:

stmt  level    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 SIGNED_CHAR
*** CODE SEGMENT '?PR?uchar?T?uchar':
    8:   if (ch1  > 0) i = ch1;
 00000000  4800  LDR   R0,=ch1 ; ch1
 00000002  7800  LDRB  R0,[R0,#0x0] ; ch1


 00000004  1C01  MOV   R1,R0
 00000006  2900  CMP   R1,#0x0
 00000008  DD01  BLE   L_1  ; T=0x0000000E
 0000000A  4800  LDR   R0,=i ; i
 0000000C  6001  STR   R1,[R0,#0x0] ; i
 0000000E          L_1:
    9:   if (uch2 > 0) i = uch2;
 0000000E  4800  LDR   R0,=uch2 ; uch2
 00000010  7800  LDRB  R0,[R0,#0x0] ; uch2
 00000012  1C01  MOV   R1,R0
 00000014  2900  CMP   R1,#0x0
 00000016  DD01  BLE   L_2  ; T=0x0000001C
 00000018  4800  LDR   R0,=i ; i
 0000001A  6001  STR   R1,[R0,#0x0] ; i
 0000001C          L_2:
   10:   if (sch3 > 0) i = sch3;
 0000001C  4800  LDR   R0,=sch3 ; sch3
 0000001E  7800  LDRB  R0,[R0,#0x0] ; sch3
 00000020  0600  LSL   R0,R0,#0x18
 00000022  1600  ASR   R0,R0,#0x18
 00000024  1C01  MOV   R1,R0
 00000026  2900  CMP   R1,#0x0
 00000028  DD01  BLE   L_3  ; T=0x0000002E
 0000002A  4800  LDR   R0,=i ; i
 0000002C  6001  STR   R1,[R0,#0x0] ; i
 0000002E          L_3:
   11: }
 0000002E  4770  BX    R14
 00000030          ENDP ; 'uchar?T'
CODE SIZE: 48 Bytes
Code Generated
With SIGNED_CHAR
*** CODE SEGMENT '?PR?uchar?T?uchar':
    8:   if (ch1  > 0) i = ch1;
 00000000  4800  LDR   R0,=ch1 ; ch1
 00000002  7800  LDRB  R0,[R0,#0x0] ; ch1
 00000004  0600  LSL   R0,R0,#0x18
 00000006  1600  ASR   R0,R0,#0x18
 00000008  1C01  MOV   R1,R0
 0000000A  2900  CMP   R1,#0x0
 0000000C  DD01  BLE   L_1  ; T=0x00000012
 0000000E  4800  LDR   R0,=i ; i
 00000010  6001  STR   R1,[R0,#0x0] ; i
 00000012          L_1:
    9:   if (uch2 > 0) i = uch2;
 00000012  4800  LDR   R0,=uch2 ; uch2
 00000014  7800  LDRB  R0,[R0,#0x0] ; uch2
 00000016  1C01  MOV   R1,R0
 00000018  2900  CMP   R1,#0x0
 0000001A  DD01  BLE   L_2  ; T=0x00000020
 0000001C  4800  LDR   R0,=i ; i
 0000001E  6001  STR   R1,[R0,#0x0] ; i
 00000020          L_2:
   10:   if (sch3 > 0) i = sch3;
 00000020  4800  LDR   R0,=sch3 ; sch3
 00000022  7800  LDRB  R0,[R0,#0x0] ; sch3
 00000024  0600  LSL   R0,R0,#0x18
 00000026  1600  ASR   R0,R0,#0x18
 00000028  1C01  MOV   R1,R0
 0000002A  2900  CMP   R1,#0x0
 0000002C  DD01  BLE   L_3  ; T=0x00000032
 0000002E  4800  LDR   R0,=i ; i
 00000030  6001  STR   R1,[R0,#0x0] ; i
 00000032          L_3:
   11: }
 00000032  4770  BX    R14
 00000034          ENDP ; 'uchar?T'
CODE SIZE: 52 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.