C-cross-platform macro definition

Source: Internet
Author: User

1 #ifndef _h_included2 #define_h_included3 4#include <stdio.h>5#include <stdlib.h>6#include <stdarg.h>7#include <float.h>8#include <string.h>9#include <math.h>Ten#include <limits.h> One#include <direct.h> A  - #defineDEBUG - #defineUse_windows the  - /*********************************************/ - #ifDefined (use_windows) - #defineDir_seperator ' \ \ ' + #else - #defineDir_seperator '/' + #endif A /*********************************************/ at  - /*********************************************/ - #ifLong_max >> > 0 - #defineWord_bytes 8/* 64-bit */ - #elifInt_max >> > 0 - #defineWord_bytes 4/* 32-bit */ in #else - #defineWord_bytes 2/* 16-bit */ to #endif + /*********************************************/ -  the /*********************************************/ * #ifWord_bytes = = 8 $ Panax Notoginsengtypedef signedLongIntx; -typedef unsignedLongUintx; thetypedef signedintint32; +typedef unsignedintUInt32; A  the #elifWord_bytes = = 4 +  -typedef signedintIntx; $typedef unsignedintUintx; $typedef signedintint32; -typedef unsignedintUInt32; -  the #else - Wuyitypedef signedintIntx; thetypedef unsignedintUintx; -typedef signedLongint32; Wutypedef unsignedLongUInt32; -  About #endif/* Word_bytes */ $ /*********************************************/ -  - /*********************************************/ - #defineReal_type_float 1 A #defineReal_type_double 2 + #defineReal_type_longdouble 3 the /*********************************************/ -  $ /*********************************************/ the #ifndef Real_type the  the #ifWord_bytes = = 8 the #defineReal_bytes 8 - #defineReal_type real_type_double in #else the #defineReal_bytes 4 the #defineReal_type real_type_float About #endif/* Word_bytes */ the  the #endif/* Real_type */ the /*********************************************/ +  - /*********************************************/ the #ifReal_type = = Real_type_floatBayi  thetypedeffloatReal; the #defineReal_format "%.7g" - #defineReal_limit (n) flt_# #n - #defineMath_op (OP) op# #f the #defineMATH_S2R (S,p) (Strtof ((s), (p))) the  the #elifReal_type = = Real_type_double the  -typedefDoubleReal; the #defineReal_format "%.14g" the #defineReal_limit (n) dbl_# #n the #defineMath_op (OP) op# #d94 #defineMATH_S2R (S,p) (Strtod ((s), (p))) the  the #elifReal_type = = Real_type_longdouble the 98 #defineReal_format "%.19g" About #defineReal_limit (n) ldbl_# #n - #defineMath_op (OP) op# #l101 #defineMATH_S2R (S,p) (Strtold ((s), (p)))102 103 #else104  the #error"Numeric float type not defined"106 107 #endif108 /*********************************************/109  the /*********************************************/111typedef signed ShortInt16; thetypedef unsigned Shortuint16;113typedef signedCharint8; thetypedef unsignedCharuint8; thetypedef unsignedChar byte; thetypedef unsignedCharBoolean;117typedefvoid*Pointer;118typedefChar*Chars;119typedef FILE *File; - /*********************************************/121 122 /*********************************************/123 #defineBitsof (t) (sizeof (t) <<3)124 #defineCast_type (t, x) ((t) (x)) the #defineCast_intx (x) ((Intx) (x))126 #defineCast_uintx (x) ((Uintx) (x))127 #defineCast_int32 (x) ((Int32) (x)) - #defineCast_uint32 (x) ((UInt32) (x))129 #defineCast_int16 (x) ((Int16) (x)) the #defineCast_uint16 (x) ((uint16) (x))131 #defineCast_int8 (x) ((int8) (x)) the #defineCast_uint8 (x) ((uint8) (x))133 #defineCast_byte (x) ((byte) (x))134 #defineCast_boolean (x) ((Boolean) (!! (x)))135 #defineCast_void (x) ((void) (x))136 #defineCast_chars (x) ((Chars) (x))137 #defineCast_pointer (x) ((Pointer) (x))138 #defineStruct_new (t) ((t) calloc (1, Sizeof_type (t)))139 #defineStruct_alloc (t) ((t) malloc (Sizeof_type (t))) $ #defineArray_size (a) (sizeof (a)/sizeof (* (a)))141 #defineMath_max (x, y) ((x) > (y)? (x): (y))142 #defineMath_min (x, y) ((x) < (y)? (x): (y))143 #defineMath_swap (x, y) ((x) ^= (y) ^= (x) ^= (y))144 #defineMath_abs (x) ((x) < 0?-(x): (x))145 #defineMath_sign (x) ((x) < 0?-1: ((x)? 1:0))146 #defineMath_r2i (R, i) ((i = (r)) = = (R))147 #defineMath_pow2 (n) (1 << (n))148 /*********************************************/149  Max /*********************************************/151 #ifdef DEBUG the #defineDebug_assert (c) ((c) | | printf ("Debug>> Assertion failed:%s, #%d," #c "\ n", __file__,__line__))153 #else154 #defineDebug_assert (c) ((void) 0)155 #endif156 /*********************************************/157 158 #endif

C-cross-platform macro definition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.