Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can I declare main as void, to shut off these annoying “main returns no value\ messages?

0
Posted

Can I declare main as void, to shut off these annoying “main returns no value\ messages?

0

No. main must be declared as returning an int, and as taking either zero or two arguments, of the appropriate types. If you’re calling exit() but still getting warnings, you may have to insert a redundant return statement (or use some kind of “not reached” directive, if available). Declaring a function as void does not merely shut off or rearrange warnings: it may also result in a different function call/return sequence, incompatible with what the caller (in main’s case, the C run-time startup code) expects. That is, if the calling sequences for void- and int-valued functions differ, the startup code is going to be calling main using specifically the int-valued conventions, and if main has been improperly declared as void, it may not work. (See also question 2.18.) (Note that this discussion of main pertains only to “hosted” implementations; none of it applies to “freestanding” implementations, which may not even have main. However, freestanding implementations are comparatively

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123