Why is it dangerous?
- From: Julian <juli@xxxxxxxxxxxxxx>
- Date: Sun, 10 Aug 2008 02:42:27 +0200 (CEST)
'evening.
I'm not new to C and have been programming in it since I was 8 but
here's a strange problem I've never seen before.
When I compile a program from our C course with a windows compiler
there is no problem but when I try to compile it with a linux compiler
it complains that
a_03.c:(.text+0x4d): warning: the `gets' function is dangerous
and should not be used.
Is linux more dangerous than windows? Where can I download a
non dangerous gets function? I have never used gets before is
there undefined behavior somewhere?
Here is a trimmed down example program from my assignment that
demonstrates the problem
#include <stdio.h>
#include <malloc.h>
void main()
{
char *string;
printf("enter string (max 2000 chars): ");
fflush(stdin);
fflush(stdout);
string = (char *)malloc(2001);
if(!string) exit(1);
gets(string);
printf("you entered: %s\n", string);
free(string);
exit(0);
}
On windows with TurboC and Lcc no error is printed. On linux with
gcc it says gets is dangerous.
Please advise my instructor says gcc is overly pedantic.
.
- Follow-Ups:
- Re: Why is it dangerous?
- From: Bart
- Re: Why is it dangerous?
- From: Paul Hsieh
- Re: Why is it dangerous?
- From: Keith Thompson
- Re: Why is it dangerous?
- From: Gordon Burditt
- Re: Why is it dangerous?
- From: s0suk3
- Re: Why is it dangerous?
- From: Ian Collins
- Re: Why is it dangerous?
- From: Richard Heathfield
- Re: Why is it dangerous?
- Prev by Date: Re: Variable naming conventions.
- Next by Date: Re: Why is it dangerous?
- Previous by thread: where do the automatic variables go ?
- Next by thread: Re: Why is it dangerous?
- Index(es):
Relevant Pages
|