`
haoningabc
  • 浏览: 1448511 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

intptr_t 其实不是指针类型 (转载)

c 
阅读更多
原文地址http://blog.163.com/james_huangjian/blog/static/178049345201261643452479/

eflag寄存器
http://www.cnblogs.com/shenlian/archive/2011/05/22/2053857.html

intptr_t 其实不是指针类型  

2012-07-16 16:34:52|  分类: C++ |字号 订阅
intptr_t 其实不是指针类型
分类: C语言 2012-04-23 17:26 336人阅读 评论(0) 收藏 举报
 最近在看nginx源码,看到有一个类型intptr_t,没有见过,google了一下,有人说是指针类型,但是看nginx源码中对该类型变量的使用,好像不是指针类型。

[cpp] view plaincopy
static ngx_int_t  
 667 ngx_get_options(int argc, char *const *argv)  
 668 {  
 669     u_char     *p;  
 670     ngx_int_t   i;  
 671   
 672     for (i = 1; i < argc; i++) {  
 673   
 674         p = (u_char *) argv[i];  
 675   
 676         if (*p++ != '-') {  
 677             ngx_log_stderr(0, "invalid option: \"%s\"", argv[i]);  
 678             return NGX_ERROR;  
 679         }  
 680   
 681         while (*p) {  
 682   
 683             switch (*p++) {  
 684   
 685             case '?':  
 686             case 'h':  
 687                 ngx_show_version = 1;  
 688                 ngx_show_help = 1;  
 689                 break;  
其中ngx_int_t的定义如下:
[cpp] view plaincopy
78 typedef intptr_t        ngx_int_t;  


于是在linux的头文件中查找这个类型的定义,在/usr/include/stdint.h这个头文件中找到了这个类型的定义(不知道怎么在这里插入图片,所以使用文字):

                           

[cpp] view plaincopy
117 /* Types for `void *' pointers.  */  
118 #if __WORDSIZE == 64  
119 # ifndef __intptr_t_defined  
120 typedef long int        intptr_t;  
121 #  define __intptr_t_defined  
122 # endif  
123 typedef unsigned long int   uintptr_t;  
124 #else  
125 # ifndef __intptr_t_defined  
126 typedef int         intptr_t;  
127 #  define __intptr_t_defined  
128 # endif  
129 typedef unsigned int        uintptr_t;  
130 #endif  

很明显intptr_t不是指针类型,但是上边的一句注释(/* Types for `void *' pointers. */)让人很疑惑。既然不是指针类型,但是为什么说类型是为了“void *”指针?
又查了一下在《深入分析Linux内核源码》中找到了答案,原文描述如下:

尽管在混合不同数据类型时你必须小心, 有时有很好的理由这样做. 一种情况是因为内存存取, 与内核相关时是特殊的. 概念上, 尽管地址是指针, 内存管理常常使用一个无符号的整数类型更好地完成; 内核对待物理内存如同一个大数组, 并且内存地址只是一个数组索引. 进一步地, 一个指针容易解引用; 当直接处理内存存取时, 你几乎从不想以这种方式解引用
分享到:
评论

相关推荐

    用于STM32,GD32等单片机的消息队列设计源码

    intptr_t MsgQueue_PostMsg(msg_queue_t * pMsgQueue, const uint16_t msgId, const uintptr_t param); intptr_t MsgQueue_PostDelayedMsg(msg_queue_t * pMsgQueue, const uint16_t msgId, const uintptr_t param,...

    c___s_t_d_i_n_t_._h_____c(C语言 库文件)

    intptr_t uintptr_t Integer type capable of holding a value converted from a void pointer and then be converted back to that type with a value that compares equal to the original pointer. Optional: ...

    C#中的IntPtr

    C#中的IntPtr类型称为“平台特定的整数类型”,它们用于本机资源,如窗口句柄。 资源的大小取决于使用的硬件和操作系统,但其大小总是足以包含系统的指针(因此也可以包含资源的名称)。 例如,我们可以在vs2008...

    基于Libvlc库的c#中可进行录制/录像功能源码

    public static libvlc_media_player_t Create_MediaPlayer(libvlc_instance_t libvlc_instance, IntPtr handle) { libvlc_media_player_t libvlc_media_player = IntPtr.Zero; try { if (libvlc_instance == ...

    vlc-2.1.3 带录像功能的封装库

    extern public static IntPtr libvlc_new(int argc, IntPtr argv); //创建播放器实例 [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr libvlc_media_player_...

    vlc-2.2.6 带录像功能的封装库.zip

    extern public static IntPtr libvlc_new(int argc, IntPtr argv); //创建播放器实例 [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr libvlc_media_player_...

    AOCR.DLL(破解)

    验证码识别利器 private const string OCR_DLL_... IntPtr ptr; ptr = com_asprise_ocr_recognize(_handle.ToInt64(), Application.StartupPath + "\\yzm.bmp", -1, -1, -1, -1, -1, "all", "text", "", "|", "=");

    Asprise OCR 5.01 破解

    public static extern IntPtr com_asprise_ocr_recognize(Int64 handle, string imgFiles, int pageIndex, int startX, int startY, int width, int height, string recognizeType, string outputFormat, string ...

    elf-parser:没有外部依赖性的轻量级elf二进制解析器-节,符号,重定位,段

    std:: intptr_t section_offset, section_addr; std::string section_name; std::string section_type; int section_size, section_ent_size, section_addr_align;} section_t ; 使用elf解析器获取elf节# include ...

    Csharp_VLC.zip

     internal static extern libvlc_media_t libvlc_media_new_location(libvlc_instance_t libvlc_instance, IntPtr path);  //从本地文件路径构建一个libvlc_media  [DllImport("libvlc", CallingConvention...

    Nginx_study:学习Nginx原始码和架构

    Nginx_study编写说明本次学习二进制分为多个阶段第一阶段:完成逐步架构,基本功能,各模块能独立运行阶段一1.1封装整形intptr_t长度总是所在平台的数字,32位系统为4字节,64位系统为8字节1.2数据结构 ngy_buf_t是...

    wince 进程间通讯COPYDATA

    private IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) 还有个线路,用MessageWindow 在ce上不直接覆盖虚函数,ce的msgloop更新到MessageWindow 独立类里,需要自己写个类,挂这个类到窗体...

    公司用的trace记录

    intptr_t hand = _findfirst( "E:\\source\\repos\\trace\\Debug\\*.tlog", &fileinfo; ); if( hand == -1 ) { return; } files.push_back( fileinfo.name ); while( _findnext( hand, &fileinfo; ) == 0 ) ...

    闪烁应用程序窗体,不用timer控件,C#源代码[DllImport("User32")] public static extern bool FlashWindow(IntPtr hWnd, bool bInvert); try

    闪烁应用程序窗体,不用timer控件,C#源代码[DllImport("User32")] public static extern bool FlashWindow(IntPtr hWnd, bool bInvert); try { int MyTimes = 50; int MyTime = 50; for (int MyCount = 0; ...

    [编译x64程序] EplOnCpp Build 20190406 (Concept Preview)-易语言

    Only Chinese document is ...intptr_t 非算术基本类型 - 文本型 e::system::string 字节集 e::system::bin 日期时间型 e::system::datetime 子程序指针 e::system::methodptr 通用型 e::system::any 高级类型 -

    运动控制板卡类库 LTDMC.dll

    public delegate uint DMC3K5K_OPERATE(IntPtr operate_data); public partial class DmcFunc { //设置和读取打印模式(适用于所有脉冲/总线卡) [DllImport("LTDMC.dll", EntryPoint = "dmc_set_debug_mode", ...

    c# CF 拨打电话

    private static extern IntPtr SimReadRecord(IntPtr hSim, IntPtr dwAddress, IntPtr dwRecordType, IntPtr dwIndex, byte[] lpData, IntPtr dwBufferSize, ref IntPtr lpdwBytesRead); [DllImport("cellcore....

    C#判断本地文件是否处于打开状态的方法

    本文实例讲述了C#判断本地文件是否处于打开状态的方法。分享给大家供大家参考。具体分析如下: ... private static extern IntPtr _lopen(string lpPathName, int iReadWrite); [DllImport(kernel32.dll

    海康视频卡动态库

    public enum VideoStandard_t : uint { /// /// 无视频信号 /// StandardNone = 0x80000000, /// /// NTSC制式 /// StandardNTSC = 0x00000001, /// /// PAL制式 /// StandardPAL = 0x00000002,...

    菜单自绘美化漂亮的样式

    static extern IntPtr SendMessage(IntPtr Handle, Int32 msg, IntPtr wParam, IntPtr lParam); const Int32 LVM_FIRST = 0x1000; // List messages const Int32 LVM_GETHEADER = LVM_FIRST + 31; const Int32...

Global site tag (gtag.js) - Google Analytics