TAU G2错误信息:Dereferencing of NULL pointer.

在进行TAU G2编程时经常会遇到下面的错误信息:

*************************** ERROR **************************

Dereferencing of NULL pointer.

Pointer assigned new data area at address .

 有必要详细说明一下。

 一般出现这个问题,都是在访问一个类或结构的变量时出现的,例如下面是程序的片段。

None.gif D_attach_detach_group_identity   D_attach_detach_group_identity_type;
None.gif
None.gifGroup_identity_downlink          Group_identity_downlink_type;
None.gif
None.gifGroup_identity_downlinks         Group_identity_downlinks_type;
None.gif
None.gifCArray
< Group_identity_downlink,  63 >  data;
None.gif
None.gifD_attach_detach_group_identity_type.pdu_type
= 10 ;
None.gif
None.gifD_attach_detach_group_identity_type.group_identity_report
= false ;
None.gif
None.gifD_attach_detach_group_identity_type.group_identity_acknowlegement
= true ;
None.gif
None.gifD_attach_detach_group_identity_type.group_identity_attach_detach_mode
= true ;
None.gif
None.gifD_attach_detach_group_identity_type.O_Bit
= true ;
None.gif
None.gifD_attach_detach_group_identity_type.M_Bit
= true ;
None.gif
None.gifGroup_identity_downlink_type.Is_gIADTI_Present
= true ;
None.gif
None.gifGroup_identity_downlink_type.gIADTI 
=  detach;
None.gif
None.gifGroup_identity_downlink_type.group_id_attach_or_detach.group_id_detachment_downlink
= 3 ;
None.gif
None.gifGroup_identity_downlink_type.Is_gIAT_Present
= true ;
None.gif
None.gifGroup_identity_downlink_type.gIAT 
=  gssi;
None.gif
None.gifGroup_identity_downlink_type.group_id_address.group_short_subscriber_identity
= 1 ;
None.gif
None.gifD_attach_detach_group_identity_type.group_identity_downlinks.data[
0 ] = Group_identity_downlink_type;
None.gif
None.gifD_attach_detach_group_identity_type.group_identity_downlinks.NoOfRepeatedElements 
=   1 ;
None.gif
None.gif

 
在这个程序中,访问D_attach_detach_group_identity_typeGroup_identity_downlink_typeGroup_identity_downlinks_type这三个变量的成员时都会报告错误。虽然可以忽略这个错误继续运行,但是如果这个错误很多,却是非常麻烦。为什么会出现这个错误呢?

 最主要的原因是在TAU G2中,类或结构体变量都是看作指针的,如果在WATCH窗口看这些变量,在访问变量前,它们都是null,而在赋值之后会显示变量的地址,这和C语言对指针变量的处理基本相同。所以在给这些变量第1次赋值的时候就会报告访问空指针。如果想避免这个问题,就应该在赋值前先使用new关键词分配空间。如:

None.gif CArray < Group_identity_downlink,  63 >  data;
None.gif
None.gifD_attach_detach_group_identity_type 
=   new  D_attach_detach_group_identity();
None.gif
None.gifGroup_identity_downlink_type 
=   new  Group_identity_downlink();
None.gif
None.gifD_attach_detach_group_identity_type.pdu_type
= 10 ;
None.gif
None.gifD_attach_detach_group_identity_type.group_identity_report
= false ;
None.gif
None.gifD_attach_detach_group_identity_type.group_identity_acknowlegement
= true ;
None.gif
None.gifD_attach_detach_group_identity_type.group_identity_attach_detach_mode
= true ;
None.gif
None.gif……
None.gif
None.gif



这样就可以避免出现此类问题了。

转载于:https://www.cnblogs.com/zealsoft/archive/2007/03/08/667886.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值