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

  • Home
  • SEARCH
  • 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 7887615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:37:33+00:00 2026-06-03T05:37:33+00:00

If I write a program like the following one, g++ and visual studio have

  • 0

If I write a program like the following one, g++ and visual studio have the courtesy of warning me that the local variable a is never used :

int main()
{
    int a; // An unused variable? Warning! Warning!
}

If I remove the unused variable (to make the compiler happy), it leaves me with the following program :

int main()
{
    // An empty main? That's fine.
}

Now, I am left with a useless program.

Maybe I am missing something, but, if an unused variable is bad enough to raise a warning, why would an empty program be ok?

The example above is pretty simple. But in real life, if I have a big program with an empty main (because I forgot to put anything in it). Then having a warning should be a good thing, isn’t it.

Maybe I am missing an option in g++ or visual studio that can raise a warning/error when the main is empty?

  • 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-03T05:37:35+00:00Added an answer on June 3, 2026 at 5:37 am

    The reason for this is simple, if there is no return statement in main it implicitly returns EXIT_SUCCESS, as defined by the standard.

    So an empty main is fine, no return needed, no function calls needed, nothing.


    To answer the question why GCC doesn’t warn you is because warnings are there to help you with common mistakes. Leaving a variable unused can lead to confusing errors, and code bloat.

    However forgetting entirely to write a main function isn’t a common mistake by anything but a beginner and isn’t worth warning about (because it’s entirely legal as well).

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

Sidebar

Related Questions

I have a C program like the one below. I am trying to write
I have a program that looks like this. I need to consistently write something
I have to write a program that performs highly computationally intensive calculations. The program
Say I have a file, t.txt, that contains the following two lines: one two
Suppose that one has some lock based code like the following where mutexes are
I am trying to write one portion of my huge C# program that allows
I have a C console program in VS2010 that I would like to edit/debug/build
For example, how would I write a program like senuti ? Are there any
I would like to write a vulnerable program, to better understand Stack Overflow (causes)
I'm writing a blackjack program and would like to be able to write the

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.