473,394 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Reason # %ld not to use void main()

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
Jan 2 '08 #1
9 1687
mr*******@gmail.com 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.
Jan 2 '08 #2
On Jan 2, 2:55 pm, Martin Ambuhl <mamb...@earthlink.netwrote:
mrdarr...@gmail.com 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
Jan 2 '08 #3
In article <5u*************@mid.individual.net>,
Martin Ambuhl <ma*****@earthlink.netwrote:
>mr*******@gmail.com 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.

Jan 2 '08 #4
mr*******@gmail.com 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.
Jan 2 '08 #5
On Jan 2, 6:04 pm, mrdarr...@gmail.com 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.
Jan 3 '08 #6
On Jan 2, 6:54 pm, andreyvul <andrey....@gmail.comwrote:
On Jan 2, 6:04 pm, mrdarr...@gmail.com 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
Jan 3 '08 #7
mr*******@gmail.com 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
Jan 3 '08 #8
On Jan 2, 11:57 pm, Richard Heathfield <r...@see.sig.invalidwrote:
mrdarr...@gmail.com 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
Jan 3 '08 #9
Richard Heathfield wrote:
>
mr*******@gmail.com 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: <mailto:Th*************@gmail.com>
Jan 4 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

192
by: Kwan Ting | last post by:
The_Sage, I see you've gotten yourself a twin asking for program in comp.lang.c++ . http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1 If you the oh so mighty...
7
by: Howard | last post by:
Hi all, with all the posts I see that have "void main()", and all the resulting corrections, I have to wonder...is there a commonly-used IDE out there that generates "void main()" by default...
3
by: APT News Address | last post by:
Sorry if this is a dumb question. I'm having a problem with a class I designed. For some reason the destructor is being called before I am done with it and I can't see a reason for it. The...
12
by: vinayakapuram | last post by:
program1 :1 main() { printf("trip" "trapas"); } output:trip traps prog 2:
9
by: questions? | last post by:
What's wrong with the following sudo-code? ****************************** # include <stdio.h> # include <string.h> char *test="I am the string you testing on"; int main(){ char *point;
12
by: Bill Pursell | last post by:
The following code generates a compiler warning when compiled with gcc -pedantic: typedef (*FUNC)(int); FUNC f; void * get_f(void) { return &f;
11
by: Siddhu | last post by:
Hai, i am student & i have struck up with the following program's output. Kindly help me to reason out why the output goes as which is given below. THE PROGRAM goes as; #include<iostream.h>...
36
by: x_knifer_x | last post by:
read the subject it says it all int main(void) is better than int main()
0
by: =?windows-1252?Q?Sch=FCle_Daniel?= | last post by:
Hi, $ cat main.cpp #include <iostream> //#define VOID void typedef void VOID; VOID foo() { std::cout << "in foo" << std::endl;
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.