📄 gtypes.h
字号:
/* GLIB - Library of useful routines for C programming * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *//* * Modified by the GLib Team and others 1997-2000. See the AUTHORS * file for a list of people on the GLib Team. See the ChangeLog * files for a list of changes. These files are distributed with * GLib at ftp://ftp.gtk.org/pub/gtk/. */#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)#error "Only <glib.h> can be included directly."#endif#ifndef __G_TYPES_H__#define __G_TYPES_H__#include <glibconfig.h>G_BEGIN_DECLS/* Provide type definitions for commonly used types. * These are useful because a "gint8" can be adjusted * to be 1 byte (8 bits) on all platforms. Similarly and * more importantly, "gint32" can be adjusted to be * 4 bytes (32 bits) on all platforms. */typedef char gchar;typedef short gshort;typedef long glong;typedef int gint;typedef gint gboolean;typedef unsigned char guchar;typedef unsigned short gushort;typedef unsigned long gulong;typedef unsigned int guint;typedef float gfloat;typedef double gdouble;/* Define min and max constants for the fixed size numerical types */#define G_MININT8 ((gint8) 0x80)#define G_MAXINT8 ((gint8) 0x7f)#define G_MAXUINT8 ((guint8) 0xff)#define G_MININT16 ((gint16) 0x8000)#define G_MAXINT16 ((gint16) 0x7fff)#define G_MAXUINT16 ((guint16) 0xffff)#define G_MININT32 ((gint32) 0x80000000)#define G_MAXINT32 ((gint32) 0x7fffffff)#define G_MAXUINT32 ((guint32) 0xffffffff)#define G_MININT64 ((gint64) G_GINT64_CONSTANT(0x8000000000000000))#define G_MAXINT64 G_GINT64_CONSTANT(0x7fffffffffffffff)#define G_MAXUINT64 G_GINT64_CONSTANT(0xffffffffffffffffU)typedef void* gpointer;typedef const void *gconstpointer;typedef gint (*GCompareFunc) (gconstpointer a, gconstpointer b);typedef gint (*GCompareDataFunc) (gconstpointer a, gconstpointer b, gpointer user_data);typedef gboolean (*GEqualFunc) (gconstpointer a, gconstpointer b);typedef void (*GDestroyNotify) (gpointer data);typedef void (*GFunc) (gpointer data, gpointer user_data);typedef guint (*GHashFunc) (gconstpointer key);typedef void (*GHFunc) (gpointer key, gpointer value, gpointer user_data);typedef void (*GFreeFunc) (gpointer data);typedef const gchar * (*GTranslateFunc) (const gchar *str, gpointer data);/* Define some mathematical constants that aren't available * symbolically in some strict ISO C implementations. * * Note that the large number of digits used in these definitions * doesn't imply that GLib or current computers in general would be * able to handle floating point numbers with an accuracy like this. * It's mostly an exercise in futility and future proofing. For * extended precision floating point support, look somewhere else * than GLib. */#define G_E 2.7182818284590452353602874713526624977572470937000#define G_LN2 0.69314718055994530941723212145817656807550013436026#define G_LN10 2.3025850929940456840179914546843642076011014886288#define G_PI 3.1415926535897932384626433832795028841971693993751#define G_PI_2 1.5707963267948966192313216916397514420985846996876#define G_PI_4 0.78539816339744830961566084581987572104929234984378#define G_SQRT2 1.4142135623730950488016887242096980785696718753769/* Portable endian checks and conversions * * glibconfig.h defines G_BYTE_ORDER which expands to one of * the below macros. */#define G_LITTLE_ENDIAN 1234#define G_BIG_ENDIAN 4321#define G_PDP_ENDIAN 3412 /* unused, need specific PDP check */ /* Basic bit swapping functions */#define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \ (guint16) ((guint16) (val) >> 8) | \ (guint16) ((guint16) (val) << 8)))#define GUINT32_SWAP_LE_BE_CONSTANT(val) ((guint32) ( \ (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \ (((guint32) (val) & (guint32) 0x0000ff00U) << 8) | \ (((guint32) (val) & (guint32) 0x00ff0000U) >> 8) | \ (((guint32) (val) & (guint32) 0xff000000U) >> 24)))#define GUINT64_SWAP_LE_BE_CONSTANT(val) ((guint64) ( \ (((guint64) (val) & \ (guint64) G_GINT64_CONSTANT (0x00000000000000ffU)) << 56) | \ (((guint64) (val) & \ (guint64) G_GINT64_CONSTANT (0x000000000000ff00U)) << 40) | \ (((guint64) (val) & \ (guint64) G_GINT64_CONSTANT (0x0000000000ff0000U)) << 24) | \ (((guint64) (val) & \ (guint64) G_GINT64_CONSTANT (0x00000000ff000000U)) << 8) | \ (((guint64) (val) & \ (guint64) G_GINT64_CONSTANT (0x000000ff00000000U)) >> 8) | \ (((guint64) (val) & \ (guint64) G_GINT64_CONSTANT (0x0000ff0000000000U)) >> 24) | \ (((guint64) (val) & \ (guint64) G_GINT64_CONSTANT (0x00ff000000000000U)) >> 40) | \ (((guint64) (val) & \ (guint64) G_GINT64_CONSTANT (0xff00000000000000U)) >> 56)))/* Arch specific stuff for speed */#if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)# if defined (__i386__)# define GUINT16_SWAP_LE_BE_IA32(val) \ (__extension__ \ ({ register guint16 __v, __x = ((guint16) (val)); \ if (__builtin_constant_p (__x)) \ __v = GUINT16_SWAP_LE_BE_CONSTANT (__x); \ else \ __asm__ ("rorw $8, %w0" \ : "=r" (__v) \ : "0" (__x) \ : "cc"); \ __v; }))# if !defined (__i486__) && !defined (__i586__) \ && !defined (__pentium__) && !defined (__i686__) \ && !defined (__pentiumpro__) && !defined (__pentium4__)# define GUINT32_SWAP_LE_BE_IA32(val) \ (__extension__ \ ({ register guint32 __v, __x = ((guint32) (val)); \ if (__builtin_constant_p (__x)) \ __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \ else \ __asm__ ("rorw $8, %w0\n\t" \ "rorl $16, %0\n\t" \ "rorw $8, %w0" \ : "=r" (__v) \ : "0" (__x) \ : "cc"); \ __v; }))# else /* 486 and higher has bswap */# define GUINT32_SWAP_LE_BE_IA32(val) \ (__extension__ \ ({ register guint32 __v, __x = ((guint32) (val)); \ if (__builtin_constant_p (__x)) \ __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \ else \ __asm__ ("bswap %0" \ : "=r" (__v) \ : "0" (__x)); \ __v; }))# endif /* processor specific 32-bit stuff */# define GUINT64_SWAP_LE_BE_IA32(val) \ (__extension__ \ ({ union { guint64 __ll; \ guint32 __l[2]; } __w, __r; \ __w.__ll = ((guint64) (val)); \ if (__builtin_constant_p (__w.__ll)) \ __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (__w.__ll); \ else \ { \ __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]); \ __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]); \ } \ __r.__ll; })) /* Possibly just use the constant version and let gcc figure it out? */# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA32 (val))# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA32 (val))# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA32 (val))# elif defined (__ia64__)# define GUINT16_SWAP_LE_BE_IA64(val) \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -