uint16_t * getRegister(std::string reg) {
// unordered_map<string, vector<uint16_t>> current_reg_map;// defined globally.
// vector current_reg_map has minimum 2 values;
uint16_t regval[current_reg_map[reg].size()];
std::copy(current_reg_map[reg].begin(), current_reg_map[reg].end(), regval);
return regval;
}
int main() {
std::string regname = "4400";
uint16_t *tmp = reader.getRegister2(regname, tmp);
std::cout<<"result "<<tmp[0]<<"\t"<<tmp[1]<<std::endl;
}
Throws segmentation fault at runtime. A lot of posts in stack overflow suggests returning a vector instead. But I explicitly require a uint16_t array as this module is part of a larger project.