posts - 27,  comments - 68,  trackbacks - 0

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

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

Dereferencing of NULL pointer.

Pointer assigned new data area at address .

  有必要详细说明一下。

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

D_attach_detach_group_identity   D_attach_detach_group_identity_type;

Group_identity_downlink          Group_identity_downlink_type;

Group_identity_downlinks         Group_identity_downlinks_type;

CArray
< Group_identity_downlink,  63 >  data;

D_attach_detach_group_identity_type.pdu_type
= 10 ;

D_attach_detach_group_identity_type.group_identity_report
= false ;

D_attach_detach_group_identity_type.group_identity_acknowlegement
= true ;

D_attach_detach_group_identity_type.group_identity_attach_detach_mode
= true ;

D_attach_detach_group_identity_type.O_Bit
= true ;

D_attach_detach_group_identity_type.M_Bit
= true ;

Group_identity_downlink_type.Is_gIADTI_Present
= true ;

Group_identity_downlink_type.gIADTI 
=  detach;

Group_identity_downlink_type.group_id_attach_or_detach.group_id_detachment_downlink
= 3 ;

Group_identity_downlink_type.Is_gIAT_Present
= true ;

Group_identity_downlink_type.gIAT 
=  gssi;

Group_identity_downlink_type.group_id_address.group_short_subscriber_identity
= 1 ;

D_attach_detach_group_identity_type.group_identity_downlinks.data[
0 ] = Group_identity_downlink_type;

D_attach_detach_group_identity_type.group_identity_downlinks.NoOfRepeatedElements 
=   1 ;


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

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

CArray < Group_identity_downlink,  63 >  data;

D_attach_detach_group_identity_type 
=   new  D_attach_detach_group_identity();

Group_identity_downlink_type 
=   new  Group_identity_downlink();

D_attach_detach_group_identity_type.pdu_type
= 10 ;

D_attach_detach_group_identity_type.group_identity_report
= false ;

D_attach_detach_group_identity_type.group_identity_acknowlegement
= true ;

D_attach_detach_group_identity_type.group_identity_attach_detach_mode
= true ;

……



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

posted on 2007-03-09 08:28 zealsoft 阅读(1151) 评论(0)  编辑 收藏 引用 所属分类: UML

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


欢迎访问我的学术博客

<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(13)

随笔分类(28)

随笔档案(27)

搜索

  •  

积分与排名

  • 积分 - 56680
  • 排名 - 391

最新评论

阅读排行榜

评论排行榜