Reason # %ld not to use void main()

M

mrdarrett

typedef struct{
int i, j;
} deStruct;

deStruct main()
{
deStruct k;

k.i = 0;
k.j = 10;
return k;
}

Crashes when running the compiled code. (I used the Borland C++ 5.5
free command line tools)

Spectacular, though.

Michael
 
M

Martin Ambuhl

typedef struct{
int i, j;
} deStruct;

deStruct main()
^^^^^^^^
main returns an int. This is an obvious error.
{
deStruct k;

k.i = 0;
k.j = 10;
return k;
main returns an int. This is an obvious error.
}

Crashes when running the compiled code. (I used the Borland C++ 5.5
free command line tools)

main returns an int. Your code is obviously erroneous.
 
M

mrdarrett

^^^^^^^^
main returns an int. This is an obvious error.



main returns an int. This is an obvious error.



main returns an int. Your code is obviously erroneous.


Yes, absolutely, of course it does return an int. And yes my code
does crash, as intended.

I was pondering why "void main(void)" shouldn't work. So, I thought,
if it's wrong to declare main as void, then it should be wrong to
declare main as arbitrary. That's what the deStruct structure (pardon
the pun) was intended to show. And crash it did...

Michael
 
K

Kenny McCormack

^^^^^^^^
main returns an int. This is an obvious error (no sh*t, Sherlock...).

Marty is a serious head case, with no concept of a sense of humor.
....
Marty is a serious head case, with no concept of a sense of humor.
....
Marty is a serious head case, with no concept of a sense of humor.
 
M

Martin Ambuhl

I was pondering why "void main(void)" shouldn't work.

Then you should have mentioned it in the body of your message.
If something is important enough to be your main concern, it should be
in the body of your message instead of the subject header, which tends
to be useless except for identifying threads.
 
A

andreyvul

Yes, absolutely, of course it does return an int. And yes my code
does crash, as intended.

I was pondering why "void main(void)" shouldn't work. So, I thought,
if it's wrong to declare main as void, then it should be wrong to
declare main as arbitrary. That's what the deStruct structure (pardon
the pun) was intended to show. And crash it did...
What compiler/machine are you using?
It compiles and runs without error on gcc-mingw and msvc 2005 on
windows xp sp2/i386.

However, gcc-mingw DOES warn about main returning non-int.
 
M

mrdarrett

What compiler/machine are you using?
It compiles and runs without error on gcc-mingw and msvc 2005 on
windows xp sp2/i386.

However, gcc-mingw DOES warn about main returning non-int.


I'm using the Borland C++ 5.5 free command line compiler.

I get a window popping up on XP... forgot the exact error. When I
return to work I can post it if you like...

Michael
 
R

Richard Heathfield

(e-mail address removed) said:
typedef struct{
int i, j;
} deStruct;

deStruct main()
{
deStruct k;

k.i = 0;
k.j = 10;
return k;
}

Crashes when running the compiled code. (I used the Borland C++ 5.5
free command line tools)

Spectacular, though.

Yeah, I crashed NT4 once with double main, in much the same spirit of
enquiry. I was rewarded with lots of blinkenlights. (A text screen
appeared, randomly filled, and the flash attribute bit was set on a good
many of the character positions.)
 
M

mrdarrett

(e-mail address removed) said:








Yeah, I crashed NT4 once with double main, in much the same spirit of
enquiry. I was rewarded with lots of blinkenlights. (A text screen
appeared, randomly filled, and the flash attribute bit was set on a good
many of the character positions.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


Wow, a double main! I'll have to try that sometime...

Michael
 
K

Kenneth Brody

Richard said:
(e-mail address removed) said:


Yeah, I crashed NT4 once with double main, in much the same spirit of
enquiry. I was rewarded with lots of blinkenlights. (A text screen
appeared, randomly filled, and the flash attribute bit was set on a good
many of the character positions.)

I tried a triple main, but it wouldn't even compile. :)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top