Re: Pointers to "why C behaves like that ?"

"Torben Ęgidius Mogensen" <torbenm@diku.dk>
24 Nov 2002 01:17:40 -0500

          From comp.compilers

Related articles
[13 earlier articles]
Re: Pointers to "why C behaves like that ?" n368714668.ch@chch.demon.co.uk (Charles Bryant) (2002-11-20)
Re: Pointers to "why C behaves like that ?" peter_flass@yahoo.com (Peter Flass) (2002-11-20)
Re: Pointers to "why C behaves like that ?" peter_flass@yahoo.com (Peter Flass) (2002-11-20)
Re: Pointers to "why C behaves like that ?" er+cc@cs.brown.edu (Manos Renieris) (2002-11-20)
Re: Pointers to "why C behaves like that ?" md9slj@mdstud.chalmers.se (Stefan Ljungstrand) (2002-11-20)
Re: Pointers to "why C behaves like that ?" torbenm@diku.dk (Torben Ęgidius Mogensen) (2002-11-24)
Re: Pointers to "why C behaves like that ?" torbenm@diku.dk (Torben Ęgidius Mogensen) (2002-11-24)
Re: Pointers to "why C behaves like that ?" nmm1@cus.cam.ac.uk (Nick Maclaren) (2002-11-24)
Re: Pointers to "why C behaves like that ?" thp@cs.ucr.edu (2002-11-24)
Re: Pointers to "why C behaves like that ?" jacob@jacob.remcomp.fr (jacob navia) (2002-11-24)
Re: Pointers to "why C behaves like that ?" nicola.musatti@objectway.it (Nicola Musatti) (2002-11-24)
Re: Pointers to "why C behaves like that ?" fjh@cs.mu.OZ.AU (Fergus Henderson) (2002-11-24)
Re: Pointers to "why C behaves like that ?" anw@merlot.uucp (Dr A. N. Walker) (2002-11-24)
[47 later articles]
| List of all articles for this month |

From: "Torben Ęgidius Mogensen" <torbenm@diku.dk>
Newsgroups: comp.compilers
Date: 24 Nov 2002 01:17:40 -0500
Organization: Department of Computer Science, University of Copenhagen
References: 02-11-059 02-11-087
Keywords: C, types, design
Posted-Date: 24 Nov 2002 01:17:40 EST

"jacob navia" <jacob@jacob.remcomp.fr> writes:


> void updateAccount(newAmount)
> {
> CurrentAmount = ReadCurrentAccount(database);
> CurrentAmunt =CurentAmount+newAmount;
> StoreDatabase(CurrentAmount);
> }


> A typo in the spelling of the variable "CurrentAmunt" in line 2
> creates a new variable "CurrentAmunt" that receives the result of the
> addition. Since the CurrentAmount variable is stored, the account
> receives a wrong value, and there is NO WAY to spot this bug until
> runtime!


"No way" is a bit of an exaggeration. The compiler can easily check
if a variable is given a value but never afterwards used. This would
typically result in a warning rather than an error (which would stop
the compiler from generating code).


Besides, any compiler will surely complain about the other spelling
mistake in the same line. :-)


Torben Mogensen


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.