1 /* promote.c -- test intergral promotion
2
3 This file is part of the LZO real-time data compression library.
4
5 Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
6 All Rights Reserved.
7
8 The LZO library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
12
13 The LZO library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with the LZO library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/lzo/
26 */
27
28 #include <stdio.h>
29
30 #if defined(_MSC_VER) && (_MSC_VER+0 >= 1000)
31 /* disable "unreachable code" warnings */
32 # pragma warning(disable: 4702)
33 #endif
34
main(int argc,char * argv[])35 int main(int argc, char *argv[])
36 {
37 unsigned char c;
38 int s;
39
40 if (argc < 0 && argv == NULL) /* avoid warning about unused args */
41 return 0;
42
43 c = (unsigned char) (1 << (8 * sizeof(char) - 1));
44 s = 8 * (int) (sizeof(int) - sizeof(char));
45
46 printf("Integral promotion: ");
47 {
48 const int u = (c << s) > 0;
49 if (u)
50 {
51 printf("Classic C (unsigned-preserving)\n");
52 printf("%d %d %uU\n", c, s, (unsigned)c << s);
53 return 1;
54 }
55 else
56 {
57 printf("ANSI C (value-preserving)\n");
58 printf("%d %d %d\n", c, s, c << s);
59 return 0;
60 }
61 }
62 }
63
64 /* vim:set ts=4 sw=4 et: */
65