ignoring return value of ‘fscanf’, declared with attribute warn_unused_result

This is a discussion on ignoring return value of ‘fscanf’, declared with attribute warn_unused_result within the C Programming forums, part of the General Programming Boards category; Hi, I was wondering if don't accept return value of fscanf and fgets, can these warnings be some potentially serious ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    159

    ignoring return value of ‘fscanf’, declared with attribute warn_unused_result

    Hi,
    I was wondering if don't accept return value of fscanf and fgets, can these warnings be some potentially serious problem:
    warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result
    warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
    Here is the code:
    Code:
    fscanf(modelfl,"%ld%*[^\n]\n", &model->kernel_parm.kernel_type); // model is just some realization of a structure
    fgets(line,(int)ll,modelfl);
    Makefile setting:
    CFLAGS= $(SFLAGS) -O3 # release C-Compiler flags
    LFLAGS= $(SFLAGS) -O3 # release linker flags
    LIBS=-L. -lm
    These warnings only occur when -O3 is specified. If nothing is specified, then there will be no warning.

    Thanks in advance!

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,474
    check return value of fscanf
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I liked the "If I turn off warnings, I don't get warnings!" part of the post.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,238
    The warnings are trying to tell you that you are ignoring the error status of those two calls, i.e. you aren't checking if they succeeded.

    The best solution is to check the return values like you should be doing.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You could just cast them to void:
    Code:
    (void) fscanf(modelfl,"%ld%*[^\n]\n", &model->kernel_parm.kernel_type); // model is just some realization of a structure
    (void) fgets(line,(int)ll,modelfl);
    But ideally it's a good idea to pay attention to what's being returned for the sake of error checking.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Alegro closes out on me
    By campsoup1988 in forum C++ Programming
    Replies: 8
    Last Post: 04-03-2006, 10:40 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  4. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 06:57 AM
  5. string class errors
    By CodeMonkey in forum C++ Programming
    Replies: 13
    Last Post: 07-20-2003, 11:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21