Home » Archimedes archive » Acorn User » AU 1994-10.adf » !Extras_Extras » CTutorial/c/Signed

CTutorial/c/Signed

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1994-10.adf » !Extras_Extras
Filename: CTutorial/c/Signed
Read OK:
File size: 015D bytes
Load address: 0000
Exec address: 0000
File contents
/* Program 'Signed' to determine whether char  */
/* variables are signed or unsigned by default */
/* on a compiler.                              */

#include <stdio.h>

main()
{
  unsigned char uch=-1;
  signed char sch=-1;
  char ch=-1;

  if(ch == uch) printf("chars are unsigned\n");
  if(ch == sch) printf("chars are signed\n");

  return 0;
}
00000000  2f 2a 20 50 72 6f 67 72  61 6d 20 27 53 69 67 6e  |/* Program 'Sign|
00000010  65 64 27 20 74 6f 20 64  65 74 65 72 6d 69 6e 65  |ed' to determine|
00000020  20 77 68 65 74 68 65 72  20 63 68 61 72 20 20 2a  | whether char  *|
00000030  2f 0a 2f 2a 20 76 61 72  69 61 62 6c 65 73 20 61  |/./* variables a|
00000040  72 65 20 73 69 67 6e 65  64 20 6f 72 20 75 6e 73  |re signed or uns|
00000050  69 67 6e 65 64 20 62 79  20 64 65 66 61 75 6c 74  |igned by default|
00000060  20 2a 2f 0a 2f 2a 20 6f  6e 20 61 20 63 6f 6d 70  | */./* on a comp|
00000070  69 6c 65 72 2e 20 20 20  20 20 20 20 20 20 20 20  |iler.           |
00000080  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000090  20 20 20 2a 2f 0a 0a 23  69 6e 63 6c 75 64 65 20  |   */..#include |
000000a0  3c 73 74 64 69 6f 2e 68  3e 0a 0a 6d 61 69 6e 28  |<stdio.h>..main(|
000000b0  29 0a 7b 0a 20 20 75 6e  73 69 67 6e 65 64 20 63  |).{.  unsigned c|
000000c0  68 61 72 20 75 63 68 3d  2d 31 3b 0a 20 20 73 69  |har uch=-1;.  si|
000000d0  67 6e 65 64 20 63 68 61  72 20 73 63 68 3d 2d 31  |gned char sch=-1|
000000e0  3b 0a 20 20 63 68 61 72  20 63 68 3d 2d 31 3b 0a  |;.  char ch=-1;.|
000000f0  0a 20 20 69 66 28 63 68  20 3d 3d 20 75 63 68 29  |.  if(ch == uch)|
00000100  20 70 72 69 6e 74 66 28  22 63 68 61 72 73 20 61  | printf("chars a|
00000110  72 65 20 75 6e 73 69 67  6e 65 64 5c 6e 22 29 3b  |re unsigned\n");|
00000120  0a 20 20 69 66 28 63 68  20 3d 3d 20 73 63 68 29  |.  if(ch == sch)|
00000130  20 70 72 69 6e 74 66 28  22 63 68 61 72 73 20 61  | printf("chars a|
00000140  72 65 20 73 69 67 6e 65  64 5c 6e 22 29 3b 0a 0a  |re signed\n");..|
00000150  20 20 72 65 74 75 72 6e  20 30 3b 0a 7d           |  return 0;.}|
0000015d