comp.lang.ada
 help / color / mirror / Atom feed
From: Hyman Rosen <hymie@prolifics.com>
Subject: Re: scope and/or parameters (beginner)
Date: 1999/04/15
Date: 1999-04-15T17:43:33+00:00	[thread overview]
Message-ID: <37162593.73F3F640@prolifics.com> (raw)
In-Reply-To: 7f52r9$n7q$1@nnrp1.dejanews.com

Robert Dewar wrote:
>   Hyman Rosen <hymie@prolifics.com> wrote:
> > Correct. A C programmer would, of course, simply declare
> > the parameter as being 'const', then insert the test
> > exactly as you did in Ada.
> 
> The "of course" here is mighty forced :-)
> 
> First, I have never *ever* seen C programmers routinely
> write prototypes with const in them, as in
> 
>    int max (const int a, const int b) {
> 
> so to claim that it is standard practice, as implied by
> your "of course" is really stretching things.

It's not standard practice to do this because generally no one cares
if the parameter is modified. No C programmer thinks of such a parameter
as being an alias of some other object. If it was important to preserve
the value of the parameter throughout the function, then making it const
is the natural solution.

> Second, please note that in C, if you *do* declare things
> this way, the effect of assigning to the const object is
> "undefined" according to the ANSI C standard, not illegal
> but undefined!

Huh? I think you have a serious misunderstanding. An attempt to assign to
a const object is illegal, and any C compiler will prevent you from doing
this. What you are thinking of is an attempt to modify an object that is
declared const through an alias that is not. Naturally, it may be impossible
to detect such an attempt, so the standard makes the effect undefined. Here's
an example:

	void f(const int a)
	{
		int *p;

		a = 1;	/* Illegal assignment to constant */
		p = &a;	/* Illegal - const discarded */
		p = (int *)&b; /* Legal because of explicit cast */
		*p = 1; /* Undefined result, but compiler need not notice. */
	}
 
> perhaps the abbreviation of constant to const is best
> interpreted as meaning that it is sort of constant, but
> not very :-) :-)

C compilers routinely place const global data into readonly segments.
I assure you, they are quite constant!




  reply	other threads:[~1999-04-15  0:00 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-02  0:00 scope and/or parameters (beginner) fluffy_pink
1999-04-03  0:00 ` Matthew Heaney
1999-04-05  0:00 ` Corey Ashford
1999-04-05  0:00   ` fluffy_doo
1999-04-06  0:00     ` Matthew Heaney
1999-04-08  0:00     ` czgrr
1999-04-10  0:00       ` fluffy_puff
1999-04-12  0:00       ` dennison
1999-04-13  0:00         ` czgrr
1999-04-13  0:00           ` Robert Dewar
1999-04-14  0:00             ` czgrr
1999-04-14  0:00               ` dennison
1999-04-14  0:00               ` Robert Dewar
1999-04-15  0:00                 ` czgrr
1999-04-15  0:00                   ` Robert Dewar
1999-04-13  0:00         ` Robert Dewar
1999-04-13  0:00     ` Robert A Duff
1999-04-14  0:00       ` Robert Dewar
1999-04-14  0:00         ` Hyman Rosen
1999-04-14  0:00           ` dennison
1999-04-14  0:00             ` Hyman Rosen
1999-04-14  0:00               ` dennison
1999-04-14  0:00                 ` Hyman Rosen
1999-04-15  0:00                   ` dennison
1999-04-15  0:00                     ` Robert Dewar
1999-04-15  0:00                       ` dennison
1999-04-15  0:00                       ` Hyman Rosen
1999-04-15  0:00           ` Robert Dewar
1999-04-15  0:00             ` Hyman Rosen [this message]
1999-04-15  0:00               ` Robert Dewar
1999-04-15  0:00                 ` Hyman Rosen
1999-04-16  0:00               ` Rakesh Malhotra
1999-04-15  0:00       ` fluffy_dong
1999-04-15  0:00         ` Robert Dewar
1999-04-15  0:00           ` dennison
1999-04-15  0:00             ` fluffy_dong
1999-04-16  0:00               ` Robert Dewar
1999-04-16  0:00                 ` Fraser Wilson
1999-04-16  0:00                   ` Gautier.DeMontmollin
1999-04-20  0:00                     ` Nick Roberts
1999-04-21  0:00                     ` fraser
1999-04-22  0:00               ` Robert A Duff
1999-04-22  0:00                 ` Larry Kilgallen
1999-04-16  0:00         ` Samuel Mize
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox