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

"jacob navia" <jacob@jacob.remcomp.fr>
15 Nov 2002 00:40:39 -0500

          From comp.compilers

Related articles
Pointers to "why C behaves like that ?" skwong@sun80.acae.cuhk.edu.hk (WONG SAI-KEE) (2002-11-12)
Re: Pointers to "why C behaves like that ?" Gayev.D.G.=?koi8-r?Q?=3Cdg=C1ev=40mail=2Eru=3E?=@m (2002-11-13)
Re: Pointers to "why C behaves like that ?" mwotton@cse.unsw.edu.au (Mark Alexander Wolton) (2002-11-15)
Re: Pointers to "why C behaves like that ?" skwong@sun80.acae.cuhk.edu.hk (WONG SAI-KEE) (2002-11-15)
Re: Pointers to "why C behaves like that ?" jacob@jacob.remcomp.fr (jacob navia) (2002-11-15)
Re: Pointers to "why C behaves like that ?" christian.bau@freeserve.co.uk (Christian Bau) (2002-11-17)
Re: Pointers to "why C behaves like that ?" Gayev.D.G.=?iso-8859-1?Q?=3Cdg=E0ev=40mail=2Eru=3E (2002-11-17)
Re: Pointers to "why C behaves like that ?" bobduff@shell01.TheWorld.com (Robert A Duff) (2002-11-17)
Re: Pointers to "why C behaves like that ?" jamesp_spam_me_not@silver-future.com (James Powell) (2002-11-17)
Re: Pointers to "why C behaves like that ?" thp@cs.ucr.edu (2002-11-17)
Re: Pointers to "why C behaves like that ?" mwotton@cse.unsw.edu.au (Mark Alexander Wolton) (2002-11-20)
[62 later articles]
| List of all articles for this month |
From: "jacob navia" <jacob@jacob.remcomp.fr>
Newsgroups: comp.compilers
Date: 15 Nov 2002 00:40:39 -0500
Organization: Wanadoo, l'internet avec France Telecom
References: 02-11-059
Keywords: design
Posted-Date: 15 Nov 2002 00:40:39 EST

> Why the C lang behaves like that:
> We need to delare variable in advance, in contrast to other
> lang, the program simply use without declaring it.
>


suppose this code:


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


You see the problem?


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!


This means that any error when writing down the name of a variable is
a fatal error that will never be spotted. C prevents this by requiring
you to explicitly state the names you want at least twice!


Post a followup to this message

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