Tags

, ,

In making some minor modifications to the main simulation program, CEG-1.4.8, I encountered a compile error using gcc 4.3.2-7. The system is 64-bit AMD based, running Fedora 10. gcc was installed from the rpm package gcc-4.3.2-7.x86_64. The simple compile command g++ -o CEG-1.4.8-SMP CEG-1.4.8-SMP.cpp yielded the following output:
CEG-1.4.8-SMP.cpp: In function ‘int main(int, char**)’:
CEG-1.4.8-SMP.cpp:75: error: ‘strcpy’ was not declared in this scope
CEG-1.4.8-SMP.cpp:114: error: ‘strcpy’ was not declared in this scope
CEG-1.4.8-SMP.cpp:281: error: ‘strcpy’ was not declared in this scope

Given that these lines refer to fairly old parts of the code, and that compilation has been successful for years, I suspected that either there is a bug in this version of gcc, this latest RH update to its gcc package, or that my code is no longer legal. It seems to be the latter, and using strcpy is not really a good idea anyway. Here’s an example of the offending code (all uses referred to file reads from command line arguments or opening files for output):
//open existing matrix file specified by user
do
{
strcpy(matrix_name,argv[2]);
std::cout << "\nName of network matrix file: " << matrix_name;
matrix_file.open(matrix_name);
}

Note the use of strcpy in the fourth line. Simply replacing the routine worked. Here’s a correction:
//open existing matrix file specified by user
do
{
const char *matrix_name = argv[2];
std::cout << "\nName of network matrix file: " << matrix_name;
matrix_file.open(matrix_name);
}

Advertisements