473,437 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,437 software developers and data experts.

unexpected result

hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so

Mar 8 '06
62 3679
ma***********@gmail.com wrote:
That guy advocating buffer overflows wrote:
I suspect Richard is big and ugly enough to do that himself.

This is really not in a good taste. I expect lot of professional
attitude from people posting in here. Words like *ugly* and
pointing to someone personally really puts me off.


In my area, "is big enough and ugly enough" is slang for
"is experienced enough", and it has no negative
connotations whatsoever.

Mar 15 '06 #51
Richard Heathfield wrote:
In 1989, I was learning C. The guy sitting next to me was learning C too. He
omitted to provide sufficient storage for a string. (He was just one byte
short.) When the program ran, he saw pretty much what he expected to see,
just general student-program output, you know the stuff - and then, at the
bottom there, it said something like:

"Do you really want to format C: (Y/N)?"

He was *very* fortunate. The result of this particular instance of undefined
behaviour appears to have been a jump into "the system" - and if it had
jumped just a bit further, he could well have had his hard drive formatted
without being asked. No, I'm not making this up.


Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?

JS
Mar 16 '06 #52

John Smith wrote:
Richard Heathfield wrote:
In 1989, I was learning C. The guy sitting next to me was learning C too. He
omitted to provide sufficient storage for a string. (He was just one byte
short.) When the program ran, he saw pretty much what he expected to see,
just general student-program output, you know the stuff - and then, at the
bottom there, it said something like:

"Do you really want to format C: (Y/N)?"

He was *very* fortunate. The result of this particular instance of undefined
behaviour appears to have been a jump into "the system" - and if it had
jumped just a bit further, he could well have had his hard drive formatted
without being asked. No, I'm not making this up.


Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?

JS


http://www.ima.umn.edu/~arnold/disasters/ariane.html

Mar 16 '06 #53
John Smith said:
Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?


If you're old enough, you may recall the Amiga home computer. IIRC some
idiot once wrote a virus "for" it, which could play a tune on the disk
drive! (I think it mucked about with the stepper motor.) This did the drive
no good whatsoever.

Admittedly, this was deliberate and malicious damage. But what can be done
through malice can also be done through incompetence. If a computer is
physically capable of damaging hardware, then yes, undefined behaviour can
certainly have that result.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 16 '06 #54
Jalapeno said:

John Smith wrote:

Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?

JS


http://www.ima.umn.edu/~arnold/disasters/ariane.html


Oh yeah - I didn't think of that. :-)

Also, let us not forget Therac-25, which, admittedly, didn't damage the
hardware. "Just" the wetware.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 16 '06 #55

"Richard Heathfield" <in*****@invalid.invalid> wrote in message
news:dv**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Jalapeno said:

John Smith wrote:

Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?

JS


http://www.ima.umn.edu/~arnold/disasters/ariane.html


Oh yeah - I didn't think of that. :-)

Also, let us not forget Therac-25, which, admittedly, didn't damage the
hardware. "Just" the wetware.


The just had a special on this on the History channel in the US, and showed
well over a dozen examples. They were predominantly rocketry of course, but
had non-rocketry examples too, from trains to nuclear plants, etc...

The one I remember was setting incorrect VGA modes on early PC's would blow
a fuse in the monitor because it couldn't handle the sync voltages for that
mode. Why do I remember that? Because, I specifically told a friend that
it was impossible for software to damage PC hardware... Live and learn!
Rod Pemberton
Mar 16 '06 #56
John Smith <JS****@mail.net> wrote:

Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?


Yes. The most common example is early PCs that used a combination of
hardware and software to generate their video output signals. Incorrect
code and/or data could result in wildly out-of-spec video signals that
would damage (possibly spectacularly) the monitors of the time, which
were not protected against such abuse.

Another example I am personally familiar with was a graphics computer
where the assembly language was more like microcode -- there were no op
codes, per se, rather the bits in the instruction specified the source
and destination of the data, the logical operation to perform on the
source and target data (assign, negate, AND, OR, XOR), an optional
rotation to be performed, etc. The standard calling conventions for the
system had argument lists inline with the code, so a call to a
subroutine consisted of the call instruction, followed by the first
argument, the second argument, etc., then the next instruction to be
executed on return from the subroutine. There was no argument count, so
variable length argument lists were, by convention, terminated by a word
with all bits set.

There was a bug in one of the standard libraries that resulted in
variable argument subroutines returning to the all ones terminator
rather than the following instruction as it should. An instruction with
all bits set was not a well-defined operation, it truely resulted in
undefined behavior, although the bit mapped nature of the instructions
made it fairly obvious what should happen. The result was mostly
innocuous, although it did have the potentially "interesting" side
effect of incrementing the very last word in memory. However, because
that particular combination of operations was not useful (hence the lack
of a defined instruction), it had never been tested, and it resulted in
a short-circuit in the processor. Since the short circuit only existed
for the duration of the instruction execution, it was not immediately
fatal, but if it happend frequently enough, it would eventually cause a
transistor to overheat and fail. It took years to figure out why one
particular transistor on one particular card in the processor had an
abnormally high failure rate.

-Larry Jones

My dreams are getting way too literal. -- Calvin
Mar 16 '06 #57
On Thu, 16 Mar 2006 14:54:04 GMT, in comp.lang.c , John Smith
<JS****@mail.net> wrote:
Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?


I broke a chain printer once by sending bad data. Caused it to try to
wind forward and back simultaneously or something.

Badly written drivers for a Matrox display card once fried my monitor.
And the original Apple had an opcode which translated into "connect
+12V rail to ground, via the CPU core".

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 16 '06 #58
la************@ugs.com writes:
John Smith <JS****@mail.net> wrote:
Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?


Yes. The most common example is early PCs that used a combination of
hardware and software to generate their video output signals. Incorrect
code and/or data could result in wildly out-of-spec video signals that
would damage (possibly spectacularly) the monitors of the time, which
were not protected against such abuse.

[snip]

On computers with old-style ferrite core memory, a tight loop that
repeatedly accessed one word of memory could cause the cores to
overheat. In extreme cases, it could literally cause a core meltdown.

On another old system, I wrote a program that attempted to do a seek
beyond the size of the disk (it was an 8-inch floppy disk). I don't
think I actually damaged the hardware, but it caused some very loud
banging.

And, of course, some embedded systems are *intended* to cause damage;
when the software detects that a timer or altimeter has reached a
specified value, the CPU gets blown up along with the bomb.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 16 '06 #59
Mark McIntyre wrote:
On Thu, 16 Mar 2006 14:54:04 GMT, in comp.lang.c , John Smith
<JS****@mail.net> wrote:
Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?


I broke a chain printer once by sending bad data. Caused it to try to
wind forward and back simultaneously or something.

Badly written drivers for a Matrox display card once fried my monitor.
And the original Apple had an opcode which translated into "connect
+12V rail to ground, via the CPU core".


IIRC the Camputers Lynx (which I had) warned you in the manuals that
address 0xFFFF was the paging register and writing the wrong value to it
would cause a bus clash that would damage the computer. I don't know if
it had a C implementation the following could easily cause real damage...
unsigned char *p = 0;
p--;
*p = 255;

Or writing through an uninitialised pointer that happened to point to
that address by chance...
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Mar 17 '06 #60
la************@ugs.com wrote:

John Smith <JS****@mail.net> wrote:

Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?


Yes. The most common example is early PCs that used a combination of
hardware and software to generate their video output signals. Incorrect
code and/or data could result in wildly out-of-spec video signals that
would damage (possibly spectacularly) the monitors of the time, which
were not protected against such abuse.

[...]

The Tandy TRS-80 Model II had its 2K video memory bank-switched with the
top 2K of "regular" memory. While switched in, the video signal was
turned off. Normally, this was something on the order of milliseconds,
and then the bank was switched out, and the video signal was turned back
on.

However, when TRS-DOS version 2 came out, it had despooler software as
a background task. It was placed at the top of memory, in the bank that
would be switched out when accessing video memory. It was also run at
the clock interrupt.

Well, if you didn't disable interrupts while accessing video memory, the
interrupt may come along with video memory switched in, and the interrupt
handler would then jump to the address where the despooler was supposed
to be, thereby locking up the computer, with the video signal off.

The design of the hardware was such that if you left the video signal
off too long, you could actually fry the hardware. (I believe it was a
flyback transformer that would burn out.)

Ask me how I know this. :-)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Mar 17 '06 #61
Keith Thompson wrote:

la************@ugs.com writes:
John Smith <JS****@mail.net> wrote:
Are you aware of a case where a software error or undefined
behavior caused actual physical damage to hardware?
[...] On computers with old-style ferrite core memory, a tight loop that
repeatedly accessed one word of memory could cause the cores to
overheat. In extreme cases, it could literally cause a core meltdown.
I suppose if the wires bent before melting, you could have a "warp
core breach"?

[...] And, of course, some embedded systems are *intended* to cause damage;
when the software detects that a timer or altimeter has reached a
specified value, the CPU gets blown up along with the bomb.


I suppose a software error there could cause damage to other hardware
as well.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Mar 17 '06 #62
On Fri, 17 Mar 2006 12:59:03 -0500, in comp.lang.c , Kenneth Brody
<ke******@spamcop.net> wrote:
Keith Thompson wrote:

On computers with old-style ferrite core memory, a tight loop that
repeatedly accessed one word of memory could cause the cores to
overheat. In extreme cases, it could literally cause a core meltdown.


I suppose if the wires bent before melting, you could have a "warp
core breach"?


only when using punched cards from an old loom.

(sorry, theres a bit of a yarn to that one)

*groan*

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 18 '06 #63

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

Similar topics

2
by: sky2070 | last post by:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in c:\inetpub\wwwroot\session.php on line 19 can anyone tell me what is wrong with this code??? <? // Define the Session...
2
by: Salim | last post by:
Hi people, keep getting this errorParse error: parse error, unexpected T_STRING in order_fns.php line 91. the code is below for the file and I've indicated line 91 <?php function...
6
by: Ehartwig | last post by:
I recently created a script for user verification, solved my emailing issues, and then re-created the script in order to work well with the new PHP 5 that I installed on my server. After...
5
by: devereaux | last post by:
I'm trying to run a script and it's throwing the following error: Parse error: syntax error, unexpected T_OBJECT_OPERATOR in openfile.php on line 41 Here is the openfile.php file and I have...
13
by: bintom | last post by:
I ran the following simple code in C++ and got unexpected results: float f = 139.4; cout << f; Output: 139.399994;
2
by: =?Utf-8?B?QXJtaW4gR2FsbGlrZXI=?= | last post by:
Hi I've got an unexpected error in a unit test. I want to test a activity from Windows Workflow Foundation (WF). First, I executed the test outside of the activity just in the test-init...
11
by: JRough | last post by:
I'm trying to use output buffering to cheat so i can print to excel which is called later than this header(). header("Content-type: application/xmsdownload"); header("Content-Disposition:...
14
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up...
14
by: Padfoot153 | last post by:
Hey, I'm getting the error: Parse error: syntax error, unexpected T_VARIABLE in /Users/Oscar/AwesomeSongz/userCake/profile.php on line 7 with this code <?php...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.