Thread: expected warning?

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    63

    expected warning?

    My current project is a basic syntax to c/c++ translator.
    In legacy code that I inherited this line


    LINE INPUT hFile,a$


    Is translated to:
    Code:
    fgets(a, 1048576, hFile);

    with a$ having the default size of a $:
    Code:
    char a[2048];
    I am curious why no (windows) compiler(gcc,PellesC) emits a warning when compiling?


    Is it a "JUST DON'T DO THAT !!" ?




    James

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Code:
    #include <stdio.h>
    
    int main() {
        char a[2048];
        fgets(a, 1048576, stdin);
        puts(a);
        return 0;
    }
    No warning for that, even with -Wall -Wextra. In general, it would be hard to provide one considering that a could be dynamically allocated.

    If a's a char array, it may be best to use:
    Code:
        fgets(a, sizeof(a), stdin);
    although if a's a pointer, that won't work.
    In that case, you have to keep track of the size.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-23-2013, 01:44 PM
  2. Replies: 1
    Last Post: 02-25-2013, 08:08 AM
  3. Replies: 4
    Last Post: 03-12-2011, 06:59 PM
  4. Replies: 9
    Last Post: 05-28-2010, 10:11 AM
  5. Replies: 13
    Last Post: 02-14-2008, 10:25 AM