473,882 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3806
ma***********@g mail.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*****@invali d.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.ne t> 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 "interestin g" 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.ne t> 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.ne t> 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_Keit h) 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.ne t> 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

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

Similar topics

2
51403
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 class class Session { // Define the properties:
2
2890
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 process_card($card_details) { // connect to payment gateway or // use gpg to encrypt and mail or // store in DB if you really want to
6
19036
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 submitting user information into my creation script, I get the following error from the page that is suppose to insert the user data into the database, create a code, then send an email out for verification. Parse error: parse error, unexpected $end in...
5
14019
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 bolded line 41. Any ideas/help would be greatly appreciated! <?php /* This file is responsible for the download of the files
13
3628
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
3433
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 method. In this case all works fine: public void TestInitialize() {
11
2944
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: attachment; header("Pragma: no-cache"); header("Expires; 0"); print "$header\n$data";
14
5520
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 all the rows which have the corresponding state. I am getting this 'Parse error: syntax error, unexpected T_STRING in /home/attorney/public_html/' on line 13 <? $username="XXXXXXXX"; $password="XXXXXX"; $database="XXXXXXXX";
14
3620
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 require_once("models/config.php"); function signinTimeStamp()
0
9931
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9777
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11108
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10830
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10403
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9557
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7113
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5781
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4601
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.