1. Problem arises
I turn my C code into C + +. In my code, a class that creates a new location data, I originally parsed a GPS string with C code and then assigned it a value. The code snippet is as follows
// Extracting NMEA-0183 Information // GPSX:NMEA Information Structure // BUF: The first address of the received GPS data buffer void Gps_analysis (nmea_msg *gpsx,uint8_t *buf) { if((strstr (constChar *) BUF,"$GPRMC"))) nmea_gprmc_analysis (gpsx,buf); // GPRMC parsing }
Originally passed in is a global structure variable, this code is not a problem.
But now I'm passing in a variable like this: a struct pointer in a class passes through the function.
class pack{ public: nmea_msg msg;}; Pack pack; Gps_analysis (&pack.msg,temp_buf);
But I found a problem, I parse the data, but this C function can not be assigned to my structure by pointers, which is very painful.
2. Problem solving
I'll try it. GPS.C in the Gps.cpp, and then change this parameter to the way the reference is passed.
void Gps_analysis (nmea_msg & gpsx,uint8_t *buf) { nmea_gprmc_analysis (&gpsx,buf); // GPRMC parsing }
But! I TM found every successful assignment, the second time will be reported segmentation fault. This makes me more sore.
Finally, I found that this is because of the value passed in, sometimes strstr cannot find the location of the parameter, the return value is null, but it also operates on NULL, this situation occurs.
C + + External function modifies the value of a class member by pointer