| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Beginner`s Questions |
Hi Patrick,
You wrote to David Burns:
PD> DB> What's VOID used for? when I make a MAIN routine, does it have to
PD> DB> be VOID?
PD>In my (not very great) experience yes ..
Your lack of experience shows a little later :-(.
PD> DB> will:
PD> DB> main(); { printf("Hello World"); }
PD> DB> work?
PD>No. Because AFAIK every C function must return a value (default being an
PD>int). So the above code really reads.
PD> int main(); /** the ; should not be there **/
PD> {
PD> printf("Hello World");
PD> };
Correct, this is K&R behaviour though, not ANSI.
PD>In order to make it work you will need something like
PD> #include
PD> void main(void) /** You don't want to return anything or receive
PD> anything **/
The "C" standard mandates that main() _always_ returns an int. If you
set it as void main(void) you still return a value to the operating
system, it's now undefined.
Conforming forms of main() are:-
int main (void) /* This is the form you want here */
int main (int argc,char *argv[]) /* Use for command line parameters */
You may also find:
int main (int argc,char *argv[], char *envp[])
This form is compiler specific and only supported by some platforms.
PD> {
PD> printf("Hello World");
PD> return;
the return should be:
return EXIT_SUCCESS;
PD> }
George
* SLMR 2.1a * Computers eliminate spare time.
--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-717904) (2:440/4)SEEN-BY: 396/1 622/419 632/371 633/260 267 270 371 634/397 635/506 728 SEEN-BY: 639/252 670/213 218 @PATH: 440/4 255/1 252/356 140/1 270/101 396/1 633/260 635/506 728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.