Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Reason # %ld not to use void main()

Reply
Thread Tools

Reason # %ld not to use void main()

 
 
mrdarrett@gmail.com
Guest
Posts: n/a
 
      01-02-2008
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
 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      01-02-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.
 
Reply With Quote
 
 
 
 
mrdarrett@gmail.com
Guest
Posts: n/a
 
      01-02-2008
On Jan 2, 2:55 pm, Martin Ambuhl <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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.



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
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      01-02-2008
In article <(E-Mail Removed)>,
Martin Ambuhl <(E-Mail Removed)> wrote:
>(E-Mail Removed) wrote:
>> typedef struct{
>> int i, j;
>> } deStruct;
>>
>> deStruct main()

> ^^^^^^^^
> 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.

 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      01-02-2008
(E-Mail Removed) wrote:

> 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.
 
Reply With Quote
 
andreyvul
Guest
Posts: n/a
 
      01-03-2008
On Jan 2, 6:04 pm, (E-Mail Removed) wrote:

> 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.
 
Reply With Quote
 
mrdarrett@gmail.com
Guest
Posts: n/a
 
      01-03-2008
On Jan 2, 6:54 pm, andreyvul <(E-Mail Removed)> wrote:
> On Jan 2, 6:04 pm, (E-Mail Removed) wrote:
>
> > 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.



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
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      01-03-2008
(E-Mail 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.)

--
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
 
Reply With Quote
 
mrdarrett@gmail.com
Guest
Posts: n/a
 
      01-03-2008
On Jan 2, 11:57 pm, Richard Heathfield <(E-Mail Removed)> wrote:
> (E-Mail 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.)
>
> --
> 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
 
Reply With Quote
 
Kenneth Brody
Guest
Posts: n/a
 
      01-04-2008
Richard Heathfield wrote:
>
> (E-Mail 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.)


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: <(E-Mail Removed)>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To void or not to void Default User C++ 3 03-14-2011 02:15 PM
What is the difference between void proba(); and void proba(void); ??? PencoOdStip@gmail.com C++ 1 05-23-2007 07:12 PM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
`void **' revisited: void *pop(void **root) Stig Brautaset C Programming 15 10-28-2003 09:03 AM



Advertisments