jstypes.h
来自「java script test programing source code」· C头文件 代码 · 共 465 行 · 第 1/2 页
H
465 行
** DESCRIPTION:** Commonly used macros for operations on compatible types.***********************************************************************/#define JS_HOWMANY(x,y) (((x)+(y)-1)/(y))#define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y))#define JS_MIN(x,y) ((x)<(y)?(x):(y))#define JS_MAX(x,y) ((x)>(y)?(x):(y))#if (defined(XP_WIN) && !defined(CROSS_COMPILE)) || defined (WINCE)# include "jscpucfg.h" /* Use standard Mac or Windows configuration */#elif defined(XP_UNIX) || defined(XP_BEOS) || defined(XP_OS2) || defined(CROSS_COMPILE)# include "jsautocfg.h" /* Use auto-detected configuration */# include "jsosdep.h" /* ...and platform-specific flags */#else# error "Must define one of XP_BEOS, XP_OS2, XP_WIN or XP_UNIX"#endifJS_BEGIN_EXTERN_C/************************************************************************** TYPES: JSUint8** JSInt8** DESCRIPTION:** The int8 types are known to be 8 bits each. There is no type that** is equivalent to a plain "char".************************************************************************/#if JS_BYTES_PER_BYTE == 1typedef unsigned char JSUint8;typedef signed char JSInt8;#else#error No suitable type for JSInt8/JSUint8#endif/************************************************************************** TYPES: JSUint16** JSInt16** DESCRIPTION:** The int16 types are known to be 16 bits each.************************************************************************/#if JS_BYTES_PER_SHORT == 2typedef unsigned short JSUint16;typedef short JSInt16;#else#error No suitable type for JSInt16/JSUint16#endif/************************************************************************** TYPES: JSUint32** JSInt32** DESCRIPTION:** The int32 types are known to be 32 bits each.************************************************************************/#if JS_BYTES_PER_INT == 4typedef unsigned int JSUint32;typedef int JSInt32;#define JS_INT32(x) x#define JS_UINT32(x) x ## U#elif JS_BYTES_PER_LONG == 4typedef unsigned long JSUint32;typedef long JSInt32;#define JS_INT32(x) x ## L#define JS_UINT32(x) x ## UL#else#error No suitable type for JSInt32/JSUint32#endif/************************************************************************** TYPES: JSUint64** JSInt64** DESCRIPTION:** The int64 types are known to be 64 bits each. Care must be used when** declaring variables of type JSUint64 or JSInt64. Different hardware** architectures and even different compilers have varying support for** 64 bit values. The only guaranteed portability requires the use of** the JSLL_ macros (see jslong.h).************************************************************************/#ifdef JS_HAVE_LONG_LONG#if JS_BYTES_PER_LONG == 8typedef long JSInt64;typedef unsigned long JSUint64;#elif defined(WIN16)typedef __int64 JSInt64;typedef unsigned __int64 JSUint64;#elif defined(WIN32) && !defined(__GNUC__)typedef __int64 JSInt64;typedef unsigned __int64 JSUint64;#elsetypedef long long JSInt64;typedef unsigned long long JSUint64;#endif /* JS_BYTES_PER_LONG == 8 */#else /* !JS_HAVE_LONG_LONG */typedef struct {#ifdef IS_LITTLE_ENDIAN JSUint32 lo, hi;#else JSUint32 hi, lo;#endif} JSInt64;typedef JSInt64 JSUint64;#endif /* !JS_HAVE_LONG_LONG *//************************************************************************** TYPES: JSUintn** JSIntn** DESCRIPTION:** The JSIntn types are most appropriate for automatic variables. They are** guaranteed to be at least 16 bits, though various architectures may** define them to be wider (e.g., 32 or even 64 bits). These types are** never valid for fields of a structure.************************************************************************/#if JS_BYTES_PER_INT >= 2typedef int JSIntn;typedef unsigned int JSUintn;#else#error 'sizeof(int)' not sufficient for platform use#endif/************************************************************************** TYPES: JSFloat64** DESCRIPTION:** NSPR's floating point type is always 64 bits.************************************************************************/typedef double JSFloat64;/************************************************************************** TYPES: JSSize** DESCRIPTION:** A type for representing the size of objects.************************************************************************/typedef size_t JSSize;/************************************************************************** TYPES: JSPtrDiff** DESCRIPTION:** A type for pointer difference. Variables of this type are suitable** for storing a pointer or pointer sutraction.************************************************************************/typedef ptrdiff_t JSPtrdiff;/************************************************************************** TYPES: JSUptrdiff** DESCRIPTION:** A type for pointer difference. Variables of this type are suitable** for storing a pointer or pointer sutraction.************************************************************************/#if JS_BYTES_PER_WORD == 8 && JS_BYTES_PER_LONG != 8typedef JSUint64 JSUptrdiff;#elsetypedef unsigned long JSUptrdiff;#endif/************************************************************************** TYPES: JSBool** DESCRIPTION:** Use JSBool for variables and parameter types. Use JS_FALSE and JS_TRUE** for clarity of target type in assignments and actual arguments. Use** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans** just as you would C int-valued conditions.************************************************************************/typedef JSIntn JSBool;#define JS_TRUE (JSIntn)1#define JS_FALSE (JSIntn)0/************************************************************************** TYPES: JSPackedBool** DESCRIPTION:** Use JSPackedBool within structs where bitfields are not desireable** but minimum and consistent overhead matters.************************************************************************/typedef JSUint8 JSPackedBool;/*** A JSWord is an integer that is the same size as a void**/#if JS_BYTES_PER_WORD == 8 && JS_BYTES_PER_LONG != 8typedef JSInt64 JSWord;typedef JSUint64 JSUword;#elsetypedef long JSWord;typedef unsigned long JSUword;#endif#include "jsotypes.h"/************************************************************************* MACROS: JS_LIKELY** JS_UNLIKELY** DESCRIPTION:** These macros allow you to give a hint to the compiler about branch** probability so that it can better optimize. Use them like this:**** if (JS_LIKELY(v == 1)) {** ... expected code path ...** }**** if (JS_UNLIKELY(v == 0)) {** ... non-expected code path ...** }*************************************************************************/#if defined(__GNUC__) && (__GNUC__ > 2)#define JS_LIKELY(x) (__builtin_expect((x), 1))#define JS_UNLIKELY(x) (__builtin_expect((x), 0))#else#define JS_LIKELY(x) (x)#define JS_UNLIKELY(x) (x)#endif/************************************************************************* MACROS: JS_ARRAY_LENGTH** JS_ARRAY_END** DESCRIPTION:** Macros to get the number of elements and the pointer to one past the** last element of a C array. Use them like this:**** jschar buf[10], *s;** JSString *str;** ...** for (s = buf; s != JS_ARRAY_END(buf); ++s) *s = ...;** ...** str = JS_NewStringCopyN(cx, buf, JS_ARRAY_LENGTH(buf));** ...*************************************************************************/#define JS_ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0])#define JS_ARRAY_END(array) ((array) + JS_ARRAY_LENGTH(array))JS_END_EXTERN_C#endif /* jstypes_h___ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?