Greets all,

I've started reading many c books in the past few weeks, and have been enjoying learning them. I followed this one example from a c book, whick demonstrates the system function which is as follows:

Code:
/*This demonstrates the system function*/ 
#include <stdio.h> 
#include <stdlib.h> 
 
int main() 
{ 
    
   /*declare a buffer to hold input*/ 
   char input[40]; 
    
   while(1) 
   { 
     
      puts("\nEnter a system command, blank to exit"); 
      gets(input); 
       
      /*Exit if input == null*/ 
      if(input[0] == '\0') 
      exit; 
 
      /*execute command*/ 
      system(input); 
   } 
   return 0; 
}
Now, it compiles and works fine, but while compiling it say's:

/tmp/ccWRQUCs.o(.text+0x28): the 'gets' function is dangerous and should not be used.
so i got curious, and didn't set and array size for input, and left it as -

Code:
char input[];
and the message about the gets function was not printed onscreen while compiling.

Why does it stop printing the gets warning when not setting a size for input? Why is the gets command so dangerous?


Thankyou very much for your time.
Regards,
Kevin.j