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

"Torben Ægidius Mogensen" <torbenm@diku.dk>
24 Nov 2002 01:14:51 -0500

          From comp.compilers

Related articles
[12 earlier articles]
Re: Pointers to "why C behaves like that ?" marcov@toad.stack.nl (Marco van de Voort) (2002-11-20)
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)
[48 later articles]
| List of all articles for this month |
From: "Torben Ægidius Mogensen" <torbenm@diku.dk>
Newsgroups: comp.compilers
Date: 24 Nov 2002 01:14:51 -0500
Organization: Department of Computer Science, University of Copenhagen
References: 02-11-059 02-11-071
Keywords: C, design
Posted-Date: 24 Nov 2002 01:14:51 EST

Gayev.D.G.=?koi8-r?Q?=3Cdg=C1ev=40mail=2Eru=3E?=@mail.rsl.ru writes:


> WONG SAI-KEE wrote:
>
> > 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.
>
> Most modern languages require variables (as well as other objects) to
> be declared before use. There are serious reasons for. The majority
> of "traditional" languages (like C, Pascal, Modulas, Ada) enforce
> strict and static (e.g. compile-time) typization model. This means
> compiler must know types of all program objects during
> compilation. Without explicit declarations, the type assigned to
> variable can only be determined by its usage - unreliable and
> sometimes rather hard to do.


Type inference is a well known and well trusted technique, and has
been used in many different languages for several decades.


As for type inference being unreliable and rather hard to do, I don't
agree. It may be a bit harder than just checking declared types, but
the complication isn't great and the technique is well-understood.


It isn't unreliable either: It has been proven that type inference in
the Hindley-Milner type system (which includes
polymorphism/genericity) will find the principal (most general) type
if one exits and report an error if one doesn't exist. Granted, the
"raw" error messages from a type inferencer can be hard to read for
the uninitiated, but many compilers reformulate these to a more
understandable form before reporting them.


If you mean that programs written using inferred types are less
reliable than programs written in languages that require explicit
declarations, I don't agree either. In my experience, the lack of
distinction in C between booleans and integers and the fact that
unions aren't type-safe are far more likely to cause unreliability
than type inference in a type-safe language.


Check Haskell (http://www.haskell.org) for a modern language with a
powerful type system and automatic type inference.


Torben Mogensen


Post a followup to this message

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