The following error message is often encountered during Tau G2 programming:
********************** ****** Error **************************
Dereferencing of NULL pointer.
Pointer assigned new data area at address.
It is necessary to describe it in detail.
Generally, this problem occurs when accessing a class or structure variable. For example, the following is a program snippet.
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;
In this program, access d_attach_detach _Group_identity _Type, Group_identity _Downlink _TypeAnd group_identity _Downlinks _TypeErrors are reported when the three variables are members. Although this error can be ignored to continue running, it is very troublesome if there are many errors. Why is this error?
The main reason is that in Tau G2, class or struct variables are treated as pointers. If you look at these variables in the watch window, they are all null before accessing the variables, the address of the variable is displayed after the value is assigned, which is basically the same as that of the C language for pointer variables. Therefore, when assigning values to these variables for 1st times, the system reports the access NULL pointer. To avoid this problem, use the new keyword to allocate space before assigning values. For example:
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;
......
This prevents such problems.