Results 1 to 4 of 4
Hi,
I am using SLES10-SP2.
I have a variable that is in scope. It has a value within the same function, but further down within the same function it looses ...
- 08-27-2009 #1Just Joined!
- Join Date
- May 2009
- Posts
- 34
Variable Lost its value
Hi,
I am using SLES10-SP2.
I have a variable that is in scope. It has a value within the same function, but further down within the same function it looses it value.
Please help.
- 08-27-2009 #2Just Joined!
- Join Date
- Aug 2009
- Posts
- 5
I'm afraid no one is going to be able to truly, really help you without first providing some code. It's impossible for us to know what's wrong with the variable without seeing what is happening to it. Post the entirety of the code, or perhaps just the offending segment if you can pinpoint it down to, like what line the variable loses its value. It may be something silly like a syntax error, or perhaps the variable never had the value in the first place (e.g. it was always zero instead of whatever you wanted) so make sure it was initialized properly. You might want to put a few checks in your code too that print the value of the variable at different points in the code. Regardless, it would be best to share the code for further analysis by others.
- 08-27-2009 #3Just Joined!
- Join Date
- May 2009
- Posts
- 34
Variable lost it value
Hi
This is the Db_flight_dep class header file
#ifndef _DB_FLT_DEP
#define _DB_FLT_DEP
#include "../include/db_columns.h"
#include "../include/db_common.h"
class Db_flight_dep : public Db_common
{
public:
int array_index ;
int airline_id ;
char call_sign[CALL_SIGN_W + 1];
int beacon_code ;
char dest[FD_DESTINATION_W + 1] ;
char ac_type[FD_AC_TYPE_W + 1] ;
char weight_class[FD_WEIGHT_CLASS_W + 1] ;
char gate[FD_GATE_W + 1] ;
char ramp[FD_RAMP_AND_DIR_W + 1] ;
char runway[FD_RUNWAY_W + 1] ;
char dep_vector[FD_DEP_VECTOR_W + 1] ;
char dep_vector_airl[FD_DEP_VECTOR_W + 1] ;
int pedigree ;
char status[FD_STATUS_W + 1];
char pred_dep_dt_time[FD_PRED_DEP_DT_TIME_W + 1];
char pred_pb_dt_time[FD_PRED_PB_DT_TIME_W + 1] ;
char pre_pb_dt_time[FD_PRE_PB_DT_TIME_W + 1] ;
char pb_dt_time[FD_PB_DT_TIME_W + 1] ;
char take_off_dt_time[FD_TAKE_OFF_DT_TIME_W + 1] ;
char tracon_exit_dt_time[FD_TRACON_EXIT_DT_TIME_W + 1] ;
int pred_taxi_dur ;
int taxi_dur ;
float tracon_pos_lat ;
float tracon_pos_long ;
int altitude ;
int ground_speed ;
int vertical_speed ;
int range ;
int azimuth ;
char cd_share_flt[FD_CODE_SHARE_FLIGHT_W + 1] ;
char obj_id[FD_OBJECT_ID_W + 1] ;
char stub_flight[FD_STUB_FLIGHT_W + 1];
inline Db_flight_dep() ;
inline ~Db_flight_dep() ;
int find_flight(const char* , const char*) ;
int find_flight(const char* , const char* , const int, const char*) ;
int create_flight(const int , char* , const char*, const int ,
const char* , const char* , const char* , const char* , const char* ,
const char* , const char* , const char* , const char* , const char* ,
const char* , const char* , const char* , const char* , const char*,
const char* , const int , const int , const float , const float ,
const int , const int, const int , const int, const int,
const char*, const char*) ;
int update_flight(const int , char* , const char*, const int ,
const char*, const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*, const char*,
const char*, const int , const int , const float, const float,
const int, const int, const int, const int, const int,
const char*, const char*) ;
int expire_flight(char*, const char*) ;
int store_index(char*, const int) ;
int get_affected_flights() ;
long get_history(const char*, const char* , const char* , const long , const long ,
char*) ;
int find_prev_flight_taxi(const char*, const char*) ;
int find_prev_flight_prop(const char*, const char*, const char*, const char*) ;
int find_prop_flights_before(const char*, const char* ,
const char*, const char* , int*) ;
int find_prop_flights_after(const char*, const char* ,
const char*, const char* , int*) ;
int delete_flight(char*, const char*) ;
} ;
inline Db_flight_dep:
b_flight_dep() {}
inline Db_flight_dep::~Db_flight_dep() {}
#endif // _DB_FLT_DEP
This is the part of the code that is affected
int Db_flight_dep::create_flight(const int inp_array_index , char* obj_id_ptr,
const char *inp_call_sign , const int inp_beacon_code ,
const char *inp_dest , const char *inp_ac_type ,
const char *inp_weight_class , const char *inp_gate ,
const char *inp_ramp , const char *inp_runway ,
const char *inp_dep_vector , const char *inp_dep_vector_airl,
const char *inp_pred_src ,
const char *inp_status , const char *inp_pred_pb_dt_time ,
const char *inp_pred_dep_dt_time , const char *inp_pre_pb_dt_time ,
const char *inp_pb_dt_time , const char *inp_to_dt_time ,
const char *inp_tracon_exit_dt_time ,
const int inp_pred_taxi_dur , const int inp_taxi_dur ,
const float inp_tracon_pos_lat, const float inp_tracon_pos_long ,
const int inp_altitude , const int inp_ground_speed ,
const int inp_vertical_speed , const int inp_range ,
const int inp_azimuth , const char *inp_cd_share_flt ,
const char *inp_stub_flt)
{
int rc = 0 ;
int airind_tmp = 0 ;
char airtmp[4] ;
char out_obj_id[19] ;
airline_id = 0 ;
memset(out_obj_id, 0, sizeof(out_obj_id));
memset(call_sign, 0, sizeof(call_sign));
beacon_code = 0 ;
memset(dest , 0, sizeof(dest));
memset(ac_type , 0, sizeof(ac_type));
memset(weight_class , 0, sizeof(weight_class));
memset(gate , 0, sizeof(gate));
memset(ramp, 0, sizeof(ramp));
memset(runway , 0, sizeof(runway));
memset(dep_vector , 0, sizeof(dep_vector));
memset(dep_vector_airl , 0, sizeof(dep_vector));
pedigree = 0 ;
memset(status , 0, sizeof(status));
/* memset(pred_pb_dt_time , 0, sizeof(pred_pb_dt_time)); */
memset(pred_pb_dt_time , 0, FD_PRED_PB_DT_TIME_W);
memset(pred_dep_dt_time, 0, sizeof(pred_dep_dt_time));
memset(pre_pb_dt_time, 0, sizeof(pre_pb_dt_time));
memset(pb_dt_time , 0, sizeof(pb_dt_time));
memset(take_off_dt_time , 0, sizeof(take_off_dt_time));
memset(tracon_exit_dt_time, 0, sizeof(tracon_exit_dt_time));
pred_taxi_dur = 0 ;
taxi_dur = 0 ;
tracon_pos_lat = 0 ;
tracon_pos_long = 0 ;
altitude = 0 ;
ground_speed = 0 ;
vertical_speed = 0 ;
range = 0 ;
azimuth = 0 ;
memset(cd_share_flt , 0, sizeof(cd_share_flt)) ;
memset(stub_flight , 0, sizeof(stub_flight)) ;
memset(airtmp, 0, sizeof(airtmp));
array_index = inp_array_index ;
// Use carrier to determine the airline_id
strncpy(airtmp, inp_call_sign, 3) ;
airtmp[(sizeof(airtmp))-1] = '\0' ;
airind_tmp = db_get_air_info(airtmp) ;
if(airind_tmp < 0)
{
if(airind_tmp == -1)
printf("Problem retrieving air_ind from data base table \n") ;
else
{
if(airind_tmp == -11)
printf("Problem inserting new airline in data base table \n") ;
}
}
else
airline_id = airind_tmp ;
strcpy(call_sign , inp_call_sign) ;
call_sign[strlen(call_sign)] = '\0' ;
beacon_code = inp_beacon_code ;
strcpy(dest , inp_dest) ;
dest[strlen(dest)] = '\0' ;
strcpy(ac_type , inp_ac_type) ;
ac_type[strlen(ac_type)] = '\0' ;
strcpy(weight_class , inp_weight_class) ;
weight_class[strlen(weight_class)] = '\0' ;
strcpy(gate , inp_gate) ;
gate[strlen(gate)] = '\0' ;
strcpy(ramp , inp_ramp) ;
ramp[strlen(ramp)] = '\0' ;
strcpy(runway , inp_runway) ;
runway[strlen(runway)] = '\0' ;
strcpy(dep_vector , inp_dep_vector) ;
dep_vector[strlen(dep_vector)] = '\0' ;
strcpy(dep_vector_airl , inp_dep_vector_airl) ;
dep_vector_airl[strlen(dep_vector_airl)] = '\0' ;
// Determine and assign value to pedigree
if(strcmp(inp_pred_src, "NONE") == 0)
pedigree = 0;
else
{
if(strcmp(inp_pred_src, "OAG") == 0)
pedigree = 10;
else
{
if(strcmp(inp_pred_src, "FP") == 0)
pedigree = 20;
else
{
if(strcmp(inp_pred_src, "FIDS") == 0)
pedigree = 30;
else
{
if(strcmp(inp_pred_src, "EDCT") == 0)
pedigree = 40;
else
{
if(strcmp(inp_pred_src, "PUSH_BACK") == 0)
pedigree = 50;
else
{
if(strcmp(inp_pred_src, "RADAR") == 0)
pedigree = 60;
else
pedigree = -1;
}
}
}
}
}
}
if (pedigree == -1) {
rc = -1;
}
else {
strcpy(status , inp_status) ;
status[strlen(status)] = '\0' ;
printf("Simon\n");
printf("%s\n", inp_pred_pb_dt_time); // This variable has the correct value
strcpy(pred_pb_dt_time , inp_pred_pb_dt_time) ;
pred_pb_dt_time[strlen(pred_pb_dt_time)] = '\0' ;
cout <<pred_pb_dt_time <<endl; //The value is okay here ******
strcpy(pred_dep_dt_time , inp_pred_dep_dt_time) ;
pred_dep_dt_time[strlen(pred_dep_dt_time)] = '\0' ;
strcpy(pre_pb_dt_time , inp_pre_pb_dt_time) ;
pre_pb_dt_time[strlen(pre_pb_dt_time) ] = '\0' ;
strcpy(pb_dt_time , inp_pb_dt_time) ;
pb_dt_time[strlen(pb_dt_time) ] = '\0' ;
strcpy(take_off_dt_time , inp_to_dt_time) ;
take_off_dt_time[strlen(take_off_dt_time) ] = '\0' ;
strcpy(tracon_exit_dt_time , inp_tracon_exit_dt_time) ;
tracon_exit_dt_time[strlen(tracon_exit_dt_time) ] = '\0' ;
pred_taxi_dur = inp_pred_taxi_dur ;
taxi_dur = inp_taxi_dur ;
tracon_pos_lat = inp_tracon_pos_lat ;
tracon_pos_long = inp_tracon_pos_long ;
altitude = inp_altitude ;
ground_speed = inp_ground_speed ;
vertical_speed = inp_vertical_speed ;
range = inp_range ;
azimuth = inp_azimuth ;
strcpy(cd_share_flt , inp_cd_share_flt) ;
cd_share_flt[strlen(cd_share_flt)] = '\0' ;
strcpy(stub_flight , inp_stub_flt) ;
stub_flight[strlen(stub_flight)] = '\0' ;
//comment out the following lines for debug
//
cout <<"+++ db_flight_dep ++++\n" << endl ;
cout << array_index << " , " << airline_id << " , " << call_sign << endl;
cout<< beacon_code << " , " << dest << " , " << ac_type << " , " << weight_class << endl;
cout<< gate << " , " << ramp << " , " << runway << " , " << endl ;
cout<< dep_vector << " , " <<dep_vector_airl << " , " << pedigree << " , " << status << " , " << endl ;
// Also the value of pred_pb_dt_time is not okay in the following line ****
cout<< pred_pb_dt_time << " , " << pred_dep_dt_time << " , " << pre_pb_dt_time << endl ;
cout<< pb_dt_time << " , " << pred_dep_dt_time << " , " << pre_pb_dt_time << endl ;
cout<< pb_dt_time << " , " << take_off_dt_time << " , " << tracon_exit_dt_time << endl ;
cout<< pred_taxi_dur << " , " << taxi_dur << " , " << tracon_pos_lat << endl ;
cout<< tracon_pos_long << " , " << altitude << " , " << ground_speed << endl ;
cout<< vertical_speed << " , " << range << " , " << azimuth << " , " << altitude <<endl ;
cout<< ground_speed << " , " << vertical_speed << " , " << range << " , " << endl ;
cout<< azimuth << " , " << cd_share_flt << " , " << out_obj_id << endl ;
cout <<"Simon" <<endl;
cout<< pred_pb_dt_time <<endl; // The value is not okay here ********
rc = db_insert_flt_dep(array_index, airline_id , call_sign ,
beacon_code , dest , ac_type , weight_class , gate , ramp , runway ,
dep_vector , dep_vector_airl, pedigree , status , pred_pb_dt_time ,
pred_dep_dt_time , pre_pb_dt_time , pb_dt_time ,
take_off_dt_time , tracon_exit_dt_time ,
pred_taxi_dur , taxi_dur , tracon_pos_lat, tracon_pos_long ,
altitude , ground_speed , vertical_speed , range , azimuth ,
cd_share_flt, stub_flight, out_obj_id);
out_obj_id[(sizeof(out_obj_id))-1] = '\0' ;
strcpy(obj_id_ptr, out_obj_id) ;
cout << "after create object_id = " << obj_id_ptr << endl ;
// exit(0);
}
return rc ;
}
The variable lost it value although it is in scope. The other variables that belong to the same object has their values.
Thx
- 08-27-2009 #4
This is a c question not really a Linux question
Guessing check the value of
FD_PRED_DEP_DT_TIME_W


Reply With Quote