I support a very old C project (the programmer who wrote them has long been gone) and I found something like this:
(Lines starting with // give the name of the file containing the following lines.)
Ads:
// db/stor_procs/sp_table.c /* Special hack prototype */ int32_t put_column_value(table_t * tab, row_t * row, u_int16_t colnum, rt_value_t * v); // db/triggers/specials.c /* BAD HACK */ int32_t put_column_value(table_t * tab, row_t * row, u_int16_t colnum, rt_value_t * v); // db_sean_add_alarm/src/rt_access.c int32_t put_column_value(struct xput_info *xptr, table_t * tab, row_t * row, u_int16_t colnum, rt_value_t * v); // db_sean_add_alarm/stor_procs/sp_table.c /* Special hack prototype */ int32_t put_column_value(table_t * tab, row_t * row, u_int16_t colnum, rt_value_t * v);
Definition:
// db/src/rt_access.c int32_t put_column_value(struct xput_info *xptr, table_t * tab, row_t * row, u_int16_t colnum, rt_value_t * v){//....} // db_sean_add_alarm/src/rt_access.c int32_t put_column_value(struct xput_info *xptr, table_t * tab, row_t * row, u_int16_t colnum, rt_value_t * v){//.....}
The programmer never declares put_column_value in the header file, but gives only the definition in the .c files. More curiously, I cannot find any definition of put_column_value that would take table_t * as the first parameter, and I am 100% sure that table_t and struct xput_info are different types (structures).
But that is not the whole story. The weird thing is that I can find put_column_value in other .c files. Now I need to clear the code, but I can’t figure out how to deal with this type C. What is the “magic” (hacking) of the original programmer used here?
The whole project is quite large, and I already tried my best to simplify this problem. Please tell me if there is any additional information necessary to solve this problem.
Edit
Find out why this project refers to another library, and this library has a function prototype definition, so this “magic” (hack) can find an implementation. Now the big problem has come to solve - this project does not have a solid unit test and it is difficult to develop for it, without testing I can’t change the codes without changing the codes, I can’t do the unit test ^ _ ^. Ahhh, maintaining legacy codes is not always a pleasant task.