PDA

View Full Version : Using old C headers in C++



glennr
October 3rd, 2007, 08:42 PM
I have some old C++ code which uses the old "std*.h" style headers and recent versions of g++ won't compile it.

Rather than change all of the headers to the new "c*" style, is there some other way to make it compile?

I couldn't find a command line switch but maybe there is one?

Wybiral
October 3rd, 2007, 08:59 PM
Despite being bad practice, I don't see why it wouldn't compile. Are you sure that's the problem?

dwhitney67
October 3rd, 2007, 09:23 PM
Please provide an example of one of your source code modules that won't compile. I would like to test it myself.

LaRoza
October 3rd, 2007, 09:32 PM
I have some old C++ code which uses the old "std*.h" style headers and recent versions of g++ won't compile it.


Give a little code, but I am thinking this "old C++" code isn't standard, at least, not now.

I have never had any problem compiling with g++ with stdio.h and friends.

glennr
October 3rd, 2007, 09:33 PM
That's what I thought too.

On further investigation, the issue is that the code uses strcpy() and includes <strings.h> but not <string.h> where strcpy is defined.

So that means I will have to change that.

Thanks for your help.

dwhitney67
October 3rd, 2007, 09:37 PM
You should also change any instance of strcpy() to strncpy().

The use of strcpy() is not secure in the sense that it can be used to overrun a buffer, and hence the stack. Many organizations that employ programming standards forbid the use of strcpy().