Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Can I declare main as void, to shut off these annoying ....
Can I declare main as void, to shut off these annoying ``main returns no value'' messages?
✍: Guest
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.
(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 rare, and if you're using one, you probably know it. If you've never heard of the distinction, you're probably using a hosted implementation, and the above rules apply.)
2015-12-20, 1263👍, 0💬
Popular Posts:
If XML does not have closing tag will it work? No, every tag in XML which is opened should have a cl...
How do we host a WCF service in IIS? Note: - The best to know how to host a WCF in IIS is by doing a...
How can I search for data in a linked list? Unfortunately, the only way to search a linked list is w...
What are the different storage classes in C? C has three types of storage: automatic, static and all...
Is There Any XSD File to Validate Atom Feed Files? - RSS FAQs - Atom Feed Introduction and File Gene...