Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8103123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:26:44+00:00 2026-06-05T23:26:44+00:00

I use scanf in a c program to read an int from STDIN: scanf(%d,

  • 0

I use scanf in a c program to read an int from STDIN:

scanf("%d", &n);

when I compile the c program with optimization enabled I get some warnings:

gcc main.c -lm -lpthread -O2 -o main
main.c: In function ‘main’:
main.c:45: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
main.c:50: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result

but when I remove the optimization options, why don’t I get those warnings?

gcc main.c -lm -lpthread -o main

P.S: I’m not using -Wall or something similar.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:26:46+00:00Added an answer on June 5, 2026 at 11:26 pm

    Changing optimizer settings changes how much (and how) the compiler analyzes your code.

    Some program flow analysis is not done when optimization is not enabled (or not set high enough), so the related warnings are not issued.
    You’ll see that frequently for “unused variable” warnings – these require analysis of the code beyond what is necessary to simply compile it, so you’ll ususally only get them with optimization enabled.

    (And you really should be compiling with -Wall.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I coded a mpi matrix multification program, which use scanf(%d, &size) , designate matrix
Is it correct to use scanf() as follows: int n; scanf([%d], &n); If so,
Again, I'm trying to make a simple program. It will read some kind of
My program has to read files that use various encodings. They may be ANSI,
I am trying to read the input from a keyboard which i will use
I was trying to make a simple bubblesort program. Read in numbers from a
I'm writing a program which will use scan conversion on triangles to fill in
I have to use scanf() for accepting name of user in NSString object. If
I'm looking to use exiftool to scan the EXIF tags from my photos and
use this website a lot but first time posting. My program creates a number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.