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 114739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:54:31+00:00 2026-05-11T02:54:31+00:00

I’m working on a C-brain teaser: Write the standard Hello-World program, without semi-colons. My

  • 0

I’m working on a C-brain teaser: Write the standard Hello-World program, without semi-colons.

My best answer so far is:

int main(void) {     if (printf('Hello World!\n'), exit(0), 0)     {         /* do nothing */     } } 

But I don’t understand why I don’t get compiler error (Visual Studio):

error C4716: 'main' : must return a value 

I’ve tried other functions with a return-type declared, but missing a return-statement, and get this compiler error.


Note that I’ve also tried:

int foo(void) {     if (printf('Hello World!\n'), exit(0), true)     {         /* do nothing */     } }  int main(void) {     foo(); } 

And don’t get a compiler error on foo. If I remove the ‘exit(0)’, I do get the compiler error. Apparently the compiler has knowledge that ‘exit’ is a special function? This seems very odd to me.

  • 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. 2026-05-11T02:54:31+00:00Added an answer on May 11, 2026 at 2:54 am

    As Jens pointed out in a comment, the posted code does not exhibit undefined behavior. The original answer here isn’t correct and doesn’t even really seem to answer the question anyway (on re-reading everything a few years later).

    The question can be summed up as, ‘why doesn’t MSVC issue warning C4716 for main() in the same circumstances it would for other functions’?

    Note that diagnostic C4716 is a warning, not an error. As far as the C language is concerned (from a standards point of view anyway), there’s never a requirement to diagnose a non-error. but that doesn’t really explain why there’s a difference, it’s just a technicality that may mean you can’t complain too much…

    The real explanation for why MSVC doesn’t issue the warning for main() when it does for other functions can really only be answered by someone on the MSVC team. As far as I can tell, the docs do not explain the difference, but maybe I missed something; so all I can do is speculate:

    In C++, the main() function is treated specially in that there’s an implicit return 0; just before the closing brace.

    I suspect that Microsoft’s C compiler provides the same treatment when it’s compiling in C mode (if you look at the assembly code, the EAX register is cleared even if there’s no return 0;), therefore as far as the compiler is concerned there is no reason to issue warning C4716. Note that Microsoft’s C mode is C90 compliant, not C99 compliant. In C90 ‘running off the end’ of main() has undefined behavior. However, always returning 0 meets the low requirements of undefined behavior, so there’s no problem.

    So even if the program in the question did run off the end main() (resulting in undefined behavior) there still wouldn’t be a warning.


    Original, not so good answer:

    In ANSI/ISO 90 C, this is undefined behavior, so MS really should produce an error (but they aren’t required to by the standard). In C99 the standard permits an implied return at the end of main() – as does C++.

    So if this is compiled as C++ or C99, there’s no error and it’s the same as return 0;. C90 results in undefined behavior (which does not require a diagnostic).

    Interestingly (well, maybe not), of the several compilers (VC9, VC6, GCC 3.4.5, Digital Mars, Comeau) I tried this on with my basic, mostly default options set (the environment I pretty much always use for quick-n-dirty testing of code snippets) the only compiler that warns about the missing return statement is VC6 when compiling as a C++ program (VC6 does not complain when compiling for C).

    Most of the compilers complain (a warning or error) if the function is not named main. Digital Mars when compiling for C does not and GCC doesn’t for C or C++.

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

Sidebar

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Karma or Protractor Karma is a JavaScript test-runner built with… May 11, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer My solution was to get the system time and add… May 11, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer Query expressions are translated into extension method calls, usually. (They… May 11, 2026 at 4:41 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.