Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

three lines of codes cause windows to reboot.

16 views
Skip to first unread message

cyberspider

unread,
Nov 1, 2001, 7:58:19 AM11/1/01
to
when run this program in debug version, windows will reboot!
#include <stdio.h>

void main()
{
int i;
for(i=0;i<5;i++)
printf("\t\t\b\b\b");

}

Who can tell me why this happens?

ke...@hplb.hpl.hp.com

unread,
Nov 1, 2001, 8:17:00 AM11/1/01
to
In article <8be402f4.01110...@posting.google.com>,

Microsoft?

--
Chris "electric hedgehog" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c.html

CBFalconer

unread,
Nov 1, 2001, 9:09:33 AM11/1/01
to

Because Windows has crawling insects. You are supposed to go out
and buy new versions until this doesn't happen, thus helping pay
for the lawyers defending Microsoft, with a chunk left over for
Bill.

--
Chuck F (cbfal...@yahoo.com) (cbfal...@XXXXworldnet.att.net)
Available for consulting/temporary embedded and systems.
(Remove "XXXX" from reply address. yahoo works unmodified)
mailto:u...@ftc.gov (for spambots to harvest)


jacob navia

unread,
Nov 1, 2001, 10:23:23 AM11/1/01
to

Richard Heathfield

unread,
Nov 1, 2001, 10:57:15 AM11/1/01
to
cyberspider wrote:
>
> when run this program in debug version, windows will reboot!
> #include <stdio.h>
>
> void main()

>From this point on, the behaviour of the program is undefined, and the C
standard makes no guarantees about its behaviour.

--
Richard Heathfield : bin...@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton

Bart Kowalski

unread,
Nov 1, 2001, 11:16:14 AM11/1/01
to
"cyberspider" <chenjian...@yahoo.com.cn> wrote in message
news:8be402f4.01110...@posting.google.com...

Please see the thread that I started here last week.


Bart.

Peter Nilsson

unread,
Nov 1, 2001, 9:21:03 PM11/1/01
to
"Bart Kowalski" <m...@nospam.com> wrote in message news:<3be1749a$0$92368$45be...@newscene.com>...

Or better yet, don't!

Any discussion of Windows gives me a headache; this ones been done to
death. What the hell's it doing on clc anyway? grumble mumble
groan... we'll be filtering out threads on wicker baskets next
...grumble moan mumble...

;)

--
Peter

The 3 Wise Men US

unread,
Nov 2, 2001, 2:10:41 AM11/2/01
to
Richard Heathfield <bin...@eton.powernet.co.uk> wrote in message news:<3BE170DB...@eton.powernet.co.uk>...

> cyberspider wrote:
> >
> > when run this program in debug version, windows will reboot!
> > #include <stdio.h>
> >
> > void main()
>
> >From this point on, the behaviour of the program is undefined, and the C
> standard makes no guarantees about its behaviour.

What do you make of this:

http://homepages.tesco.net./~J.deBoynePollard/FGA/legality-of-void-main.html

Ben Pfaff

unread,
Nov 2, 2001, 2:17:39 AM11/2/01
to
the3wi...@yahoo.com (The 3 Wise Men US) writes:

It's correct on its face, but it doesn't really address the most
important point, which is this: `int' is the only portable return
type for main().

willem veenhoven

unread,
Nov 2, 2001, 3:36:17 AM11/2/01
to
Ben Pfaff wrote:
>
> the3wi...@yahoo.com (The 3 Wise Men US) writes:
>
> > What do you make of this:
> > [link .../~J.deBoynePollard/FGA/legality-of-void-main.html]

>
> It's correct on its face, but it doesn't really address the most
> important point, which is this: `int' is the only portable return
> type for main().

"The documentation for Comeau C/C++ uses void main() in its
examples and implies that main may have a return type other
than int, but does not explicitly specify any additional
definitions of main that are allowed."

I would like to hear Greg's comment on this paragraph though ;-)

willem

Richard Heathfield

unread,
Nov 2, 2001, 4:06:14 AM11/2/01
to

It doesn't affect my statement, which is that the behaviour of the
program is not defined. The ISO C Standard does /not/ guarantee the
behaviour of a void main program. The page is referring to the fact that
implementations may, if they wish, accept void main programs, but
they've always been allowed to do that, so nothing has changed. That
they are allowed to accept those programs does /not/ mean that they are
required to translate them in the way the user intended, unless they
specifically document that they support void main. And, even if all the
implementations in the world did that (which they don't), it /still/
wouldn't be portable to putative future implementations.

Note also that the MSDN documentation it claims documents void main for
the Microsoft implementation says this: "A special function called main
is the entry point to all C++ programs." Note the plus signs.

Finally (for now!), note that it fails to mention that some
implementations reject void main outright, for example Borland in
conforming mode.

So the page is misguided and misleading IMHO.

Joona I Palaste

unread,
Nov 2, 2001, 4:13:15 AM11/2/01
to
Richard Heathfield <bin...@eton.powernet.co.uk> scribbled the following:

> The 3 Wise Men US wrote:
>> What do you make of this:
>>
>> http://homepages.tesco.net./~J.deBoynePollard/FGA/legality-of-void-main.html

(snip RH's wise words)

> Note also that the MSDN documentation it claims documents void main for
> the Microsoft implementation says this: "A special function called main
> is the entry point to all C++ programs." Note the plus signs.

Aga... aga... isn't void main() undefined behaviour in C++ too?

--
/-- Joona Palaste (pal...@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"My absolute aspect is probably..."
- Mato Valtonen

Richard Heathfield

unread,
Nov 2, 2001, 4:51:22 AM11/2/01
to
Joona I Palaste wrote:
>
> Richard Heathfield <bin...@eton.powernet.co.uk> scribbled the following:
> > The 3 Wise Men US wrote:
> >> What do you make of this:
> >>
> >> http://homepages.tesco.net./~J.deBoynePollard/FGA/legality-of-void-main.html
>
> (snip RH's wise words)
>
> > Note also that the MSDN documentation it claims documents void main for
> > the Microsoft implementation says this: "A special function called main
> > is the entry point to all C++ programs." Note the plus signs.
>
> Aga... aga... isn't void main() undefined behaviour in C++ too?

Yes, I believe so. I was merely pointing out that a reference supposedly
about C was in fact about C++.

Dan Pop

unread,
Nov 2, 2001, 8:08:04 AM11/2/01
to

Not much. First, it deals with the C99 standard, while the vast majority
of people use C89 implementations. The C89 standard doesn't contain that
loophole.

Even in the context of the C99 standard, if the implementation doesn't
*explicitly* define the effect of defining main as a void function, the
code invokes undefined behaviour.

I have *strong* doubts that the OP was using a C99 implementation
defining void main, so Richard's point seems to be entirely valid.

Dan
--
Dan Pop
CERN, IT Division
Email: Dan...@cern.ch
Mail: CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland

Noel R. Nihill

unread,
Nov 2, 2001, 9:17:41 AM11/2/01
to

"Peter Nilsson" <ai...@asiaonline.net.au> wrote in message
news:fdecbcb8.01110...@posting.google.com...

Precisely. This is a WinBug, and can be detonated using C,
Basic, Fortran, Japanse or Sanskrit. Speak no more of this!!

~N.

>
> ;)
>
> --
> Peter


-hs-

unread,
Nov 2, 2001, 9:46:11 AM11/2/01
to
Richard Heathfield <bin...@eton.powernet.co.uk> wrote in
news:3BE26206...@eton.powernet.co.uk:

> Finally (for now!), note that it fails to mention that some
> implementations reject void main outright, for example Borland in
> conforming mode.

For example (BC 3.1):

void main (void)
{
}

Compiling MAIN.C:
Error MAIN.C 2: main must have a return type of int

--
-hs- emdel at noos.fr "support Afghans against Taleban"
"Car les bandits qui sont cause des guerres
N'en meurent jamais, on n'tue qu'les innocents."
Gaston Montéhus -- La Butte Rouge

Chris Torek

unread,
Nov 2, 2001, 9:53:58 AM11/2/01
to

In article <87hesdh...@pfaff.stanford.edu>


Ben Pfaff <b...@cs.stanford.edu> wrote:
>It's correct on its face, but it doesn't really address the most
>important point, which is this: `int' is the only portable return
>type for main().

Here is an excerpt of what the page says:

... the ISO C Standard (ISO/IEC 9899:1999) ...

(In other words, this is specific to C99.)

In my opinion, this is a defect in the C Standard that needs fixing
with a corrigendum. It provides the authors of bad C programming books
with the very loophole that they have been needing for the past
decade.

(I think it is a defect myself, for other reasons; see DejaGoogle
archives of comp.std.c, for instance.)

Nonetheless, this is what the C Standard says right now, and the
several sections of the Usenet comp.lang.c FAQ document that state
that void main() is disallowed are all completely wrong.

(This is an overstatement at best, since the c.l.c FAQ predates C99.)

The C Standard currently says that an implementation is free to define
any additional forms for main that it cares to. Section 5.1.2.2.1.1 of
the C Standard lists the allowable forms for the definition of main.
Because of the semi-colon, its final sentence parses as follows:

It shall be defined
* with a return type of int and
+ with no parameters [...] or
+ with two parameters [...] or equivalent;
or
* in some other implementation-defined manner.

So if one's compiler's documentation happens to say anywhere that main
may have the return type void then main may indeed have the return
type void and a program with void main() is a conforming program.

This is all 100% correct.

The problem is, the following is also a conforming C99 program:

#include <fortran.h>
PROGRAM FOO
PRINT *, 'HELLO WORLD'
STOP
END

This program does not even require a diagnostic (although if we
drop the "#include" line, one diagnostic is required); and if a
conforming C99 compiler accepts it, it is a conforming program,
per this paragraph in C99 Section 4:

A conforming program is one that is acceptable to a
conforming implementation.

In short, the term "conforming program" is effectively useless.

Unfortunately, there is *no* term in between "conforming program"
(both the Fortran code above, and the C99 "void main", are one of
those) and "strictly conforming program" (neither example is a
strictly conforming program"). It might be nice if there were;
then we could debate whether a "void main" were this sort of "mostly
kinda portable usually as long as things go well so cross your
fingers and hope" conforming program, or more like the Fortran
"there is no way in heck this is going to work on any other
implementation even though it is conforming" conforming program. :-)

Now, the obvious problem with using "void main" is that it may
be documented for the compiler you just happen to be using today --
but what about the compiler you might have to use tomorrow? If
you have to change compilers for some reason, the new one might
*not* accept "void main". Thus, as usual, the real question is
not "is this construct conforming", but rather "does using this
construct pay off -- do I get more value out of it than it costs me?"

The answer for "void main" is almost always "no" -- it almost never
produces any value, and it almost always has at least a tiny
potential cost; and a cost of 0.0001 quatloos beats a value of
0.00000000000 quatloos, always.

(I would send this to the author of the above page, but I have no
idea how to reach him. Feel free to forward it.)
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
El Cerrito, CA, USA Domain: to...@bsdi.com +1 510 234 3167
http://claw.eng.bsdi.com/torek/ (not always up) I report spam to abuse@.

Kaz Kylheku

unread,
Nov 2, 2001, 12:40:39 PM11/2/01
to
In article <dd9a1641.01110...@posting.google.com>, The 3 Wise

This is completely laughable.

Firstly, he's using the term ``legal'' to describe a relationship between
the C and C++ standards and a language construct. Neither standard use
this term, so it is misleading and inaccurate, not to mention amateurish,
to be using it.

Secondly, he makes the mistake of assuming that just because a construct
does not require a diagnostic, it is permitted. Hence he comes to the
conclusion that void main() is not ``legal'' in C++, but ``legal'' in C.
In reality, void main() requires a diagnostic in C++, but does not
require one in C.

Lastly, he makes the fatal mistake of appealing to the term ``conforming
program'', which is known to anyone with a clue to be a useless notion.
To be a conforming program, a program has to be acceptable to an
implementation.

For example, this could be a conforming program on some implementation
somewhere:

#pragma common_lisp
(defun main () (format t "Hello, world~%"))

Clearly, this budding language lawyer is still struggling with foo,
having yet to pass bar. ;)

Greg Comeau

unread,
Nov 2, 2001, 11:13:24 PM11/2/01
to
In article <3BE25B01...@veenhoven.com>,

They've been fixed. I direct all to
http://www.comeaucomputing.com/techtalk/#voidmain
--
Greg Comeau export ETA: December See our Oct 31st special
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

0 new messages