blob: 558b17dab154f99f54bf1c95fdcc0171c69273c2 [file] [log] [blame]
Tim Peters7d3a5112000-07-08 04:17:21 +00001/***********************************************************
2Copyright (c) 2000, BeOpen.com.
3All rights reserved.
4
5See the file "Misc/COPYRIGHT" for information on usage and
6redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7******************************************************************/
8
9#ifndef Py_PYPORT_H
10#define Py_PYPORT_H 1
11
12/**************************************************************************
13Symbols and macros to supply platform-independent interfaces to basic
14C-language operations whose spellings vary across platforms.
15
16Please try to make documentation here as clear as possible: by definition,
17the stuff here is trying to illuminate C's darkest corners.
18
19Config #defines referenced here:
20
21SIGNED_RIGHT_SHIFT_ZERO_FILLS
22Meaning: To be defined iff i>>j does not extend the sign bit when i is a
23 signed integral type and i < 0.
24Used in: Py_ARITHMETIC_RIGHT_SHIFT
25**************************************************************************/
26
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/* Py_ARITHMETIC_RIGHT_SHIFT
33 * C doesn't define whether a right-shift of a signed integer sign-extends
34 * or zero-fills. Here a macro to force sign extension:
35 * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
36 * Return I >> J, forcing sign extension.
37 * Requirements:
38 * I is of basic signed type TYPE (char, short, int, long, or long long).
39 * TYPE is one of char, short, int, long, or long long, although long long
40 * must not be used except on platforms that support it.
41 * J is an integer >= 0 and strictly less than the number of bits in TYPE
42 * (because C doesn't define what happens for J outside that range either).
43 * Caution:
44 * I may be evaluated more than once.
45 */
46#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
47#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
48 ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
49#else
50#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
51#endif
52
53#ifdef __cplusplus
54}
55#endif
56
57#endif /* Py_PYPORT_H */