Page 1 of 1

Compiling help?

Posted: Tue Oct 25, 2005 9:38 am
by Mostess
C programs written by a programmer 10x more skilled than I, but written over a decade ago. I need them, I love them, I had them for UNIX, DOS, Win2k. I got the source code for my Mac (OS 10.4); I compiled them using gcc 4.0.0. They work as they should.

But they use gets() which (apparently) is unsafe. How do I know? Because they warn me every time I use them. "Warning," they say, "this program uses gets() which is unsafe." They're command-line programs that I call from shells, often in loops. So any stderr output I might want to look at is swamped with lines upon lines of these annoying warnings. I get it. It's unsafe. Shut up!

Is there a gcc commandline option that compiles the programs so they won't warn me about gets()? I really don't care how unsafe it is. Another compiler? Any quick solution short of altering the source code (a can of worms I'd like to keep shut)?

Posted: Tue Oct 25, 2005 9:56 am
by HeuristicsInc
if you just want to disable the warnings, -w claims to turn them all off.
(oh wait, it's printing this message when you run it, not compile it? bizarre)
-bill

Posted: Tue Oct 25, 2005 10:05 am
by HeuristicsInc
ah, i see - gets() is deprecated because it has no limit to the number of characters read in. some source recommends replacing with:
fgets(string, num_characters_in_string, stdin);
-bill

Posted: Tue Oct 25, 2005 10:20 am
by HeuristicsInc
Third post in a row... some googling turned up this possibility:

Note You can disable the warning by setting the environment variable DISABLE_GETS_WARNING.

That might be OS-specific so it might not work on your system.
-bill