[comp.lang.c] a couple quickies

TLIMONCE%DREW.BITNET@CUNYVM.CUNY.EDU (01/07/88)

My understanding is that the drafts and the actual standard are released
into the public domain.  Correct?  If so, would their be any problems
with someone sending copies of the next draft electronically?  If I get
a hard-copy, I can scan it into an ASCII file and send it to anyone who
asks.  Of course, I don't have $60 right now nor the time to send away
for it (and find the right address, etc).  Does ANSI take plastic? :-)
Would anyone want to split for it?  Would anyone be willing to just
send me a copy and I'll scan it and send it electronically back to them
:-) ?

I'll keep dreaming.

(new topic)
Someone asked people to grep for noalias to see (informally) how many
problems it would cause.  I came up with nothing.  I think a good reason
(well, not a good reason, but a reason.  Well, maybe a sub-good reason...)
for this is that many programmers were taught to have boolean variables
be "naturally positive".  This means that instead of a not_done variable
I was encouraged to use "done" so that my loops would be repeat... until
done, instead of repeat... until not not_done (which less readable).

Besides a small (theoretical) reduction in "noalias" conflicting with
current code, this would make me more comfortable with "excl" or
"exclusive" as a keyword instead of "noalias".  Maybe someone has an
even better suggestion that "exclusive".  Also, this is the first keyword
which is a compound word (I think).  Is this a trend?  A rose is, by any
other name, still as sweet... but I'd prefer a nice name.  :-)

(new topic)
Looking for a MakeMake routine?  The new issue of Dr. Dobb's Journal (Jan
'88) on page 61 has an advert for VersiMake which claims to re-build the
makefile for you.  Summit Information Systems, Inc., 73 East Lane,
Willingboro, NJ 08046, 1-800-334-4096.
(I am not related to Dr. Dobb's Journal other than that I buy it from my
local computer store each month.  I am not related to Summit Information
Systems, Inc. other than I saw their advert today in DDJ.  I have not
tried it and I can not vouch for it.)

(new topic)
"Is ANSI C good for systems programming?" someone asked.  I think so.  In
fact, with prototypes, one should expect more reliable programs.  I don't
think that anything thing ANSI added will be prohibiting systems
programming.

(new topic)
Does anyone use Aztec C on an Amiga?  Does anyone have their new update?
I'm waiting for mine.  They claim that their new source-level debugger is
better than CodeView.  I still want to know when they will add ANY of the
ANSI stuff to the package.  I paid a lot of money for mine and I would
like to see their updates have more than just speed improvements and bug
removals.

(new topic)
Question: Under ANSI C,
                    for (i = 0; i == 100; i++) foo(&i);
If foo() does something like: "*i = 0" will this loop ever complete?
I hope this is classified as undefined. I have seen compilers (mostly
pascal) that notice when a loop will execute an exact number of times and
create a hidden counter that does a count-down to zero to speed up the
code (compare-to-zero is usually a fast instruction).  As a side-effect,
changing the loop-variable (even as foo does) has no effect as to the
number of iterations.  ...or is this "too pascal"?

(new topic)
Sorry that I am putting all these little things into one big message.
My system is moving net-access from one machine to another so there is
no access while the move is going on.  Is it better to combine all these
messages or send out a couple short ones?


                              T. Limoncelli
  Drew U/Box 1060/Madison NJ 07940     Bitnet: tlimonce@drew.BITNET
  Disclaimer: These are my views, not my employer or Drew Univesity.
             "View this in mirror to see the secret message"
--------------------------------------------------------------------------

PEPRBV%CFAAMP.BITNET@husc6.harvard.EDU (Bob Babcock) (01/07/88)

TLIMONCE%DREW.BITNET@CUNYVM.CUNY.EDU asks
>>Question: Under ANSI C,
>>                    for (i = 0; i == 100; i++) foo(&i);
>>If foo() does something like: "*i = 0" will this loop ever complete?
>>I hope this is classified as undefined.

Seems to me that this is well defined,  and the loop should never
terminate.   But I'm not sure that the answer doesn't change if i
is declared noalias.

chris@mimsy.UUCP (Chris Torek) (01/07/88)

In article <11140@brl-adm.ARPA> TLIMONCE%DREW.BITNET@CUNYVM.CUNY.EDU writes:
>My understanding is that the drafts and the actual standard are released
>into the public domain.  Correct?

No.  The drafts and the standard are copyright by ANS.

>If so, would their be any problems with someone sending copies of
>the next draft electronically?

Yes.

Also, due to reasons that apparently boil down to `we never did
it that way before and it would be hard to start now' [*], you
cannot buy it in electronic form.  [*`We' is not X3J11.  There
is some sort of political split between the groups that do the
standards and the group(s) that publish the standard, such that
neither has much influence on the other.  This is all second (or
worse) hand information.]

>(new topic)
>"Is ANSI C good for systems programming?" someone asked.  I think so.  In
>fact, with prototypes, one should expect more reliable programs.

I think prototypes are a Good Thing.  I am not at all certain that
they should be in the (first?) C standard.  (Indeed, I happen to
believe that when prototypes are added, default declarations should
be removed entirely.  Combining the two just makes the language
awkward.)

>(new topic)
>Question: Under ANSI C,
>                    for (i = 0; i == 100; i++) foo(&i);
>If foo() does something like: "*i = 0" will this loop ever complete?

The loop will not run at all unless you use a different test.  I
assume you mean something like

	for (i = 0; i < 100; i++) foo(&i);

If foo is `foo (int *ip) { *ip = 0; }', the loop does not terminate.
How `noalias' affects this I do not know.

>I hope this is classified as undefined.

I hope not!

The for loop `for (init; test; iterate) body;' is defined as being
approximately equivalent to

	init;
	while (test) {
		body;
		iterate;
	}

If the compiler discovers that `foo' neither reads nor alters i,
it could then rewrite the loop as

	<hidden variable> = 100;
	while (--<hidden variable> >= 0)
		foo(&i);
	i = 100;

If the loop does read i but does not alter it, the compiler may use

	<hidden variable> = 100, i = 0;
	while (--<hidden variable> >= 0) {
		foo(&i);
		i++;
	}

Unless there is a great deal of code inside the loop that uses i,
or comparison against zero rather than a constant (or register, if
there is a spare register that can hold 100, or any other weird
permutation), none of these changes is likely to make much difference.
In the case where it does make such a difference, yet foo alters
i, the compiler can do this:

	i = 0;
	while (i < 100) {
		foo(&i);
		<shadow> = i;
		<body using <shadow> in place of i>;
		i = <shadow>;
	}

or perhaps this:

	<shadow> = 0;
	while (<shadow> < 100) {
		<code using <shadow>>;
		i = <shadow>;
		foo(&i);
		<shadow> = i;
		<more code using <shadow>>;
	}
	i = <shadow>;		/* if needed */

Which (if any) of these is most efficient is very machine
dependent.  Doing a perfect job of discovering whether `foo'
reads and/or alters `i' is difficult (equivalent to solving
the halting problem).  Doing a suitably good job is easy
(opinion).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

gwyn@brl-smoke.ARPA (Doug Gwyn ) (01/07/88)

In article <11140@brl-adm.ARPA> TLIMONCE%DREW.BITNET@CUNYVM.CUNY.EDU writes:
>My understanding is that the drafts and the actual standard are released
>into the public domain.  Correct?

I can't give a definitive answer to this.  The X3J11 committee working
drafts have been neither Copyright nor published.  Some standards are
Copyright, but I don't know if any ANSI or ISO standards are nor whether
this one will be.  That is not something that X3J11 decides.

>If so, would their be any problems
>with someone sending copies of the next draft electronically?  If I get
>a hard-copy, I can scan it into an ASCII file and send it to anyone who
>asks.

The master source for the draft is troff input, using a possibly modified
version of the -mm macros, I believe.  It has not been made available
electronically to anybody that I know of, despite requests, because it
is not in the committee's charter and there is no volunteer to take care
of doing this.  Until the question about Copyright is resolved, you
shouldn't copy the document in any form.

>"exclusive" as a keyword instead of "noalias".  Maybe someone has an
>even better suggestion that "exclusive".  Also, this is the first keyword
>which is a compound word (I think).  Is this a trend?

The second choice for the name was "unaliased", which is still somewhat
negative in tone.  I don't think the name matters too much so long as
it's an unusal formation (to avoid conflicts with existing code).

I doubt that it's a "trend".  It was with great reluctance that even
this keyword was added; there shouldn't be any more.

>                    for (i = 0; i == 100; i++) foo(&i);
>If foo() does something like: "*i = 0" will this loop ever complete?

No (assuming the last `i' is a pointer to the earlier one), for the
obvious reason.  C loop indices are not special, they're just variables.
There are enough sequence points that all side-effects occur within the
loop body, so the test `i == 100' will see 0 in `i' each time.

There are ways using "noalias" that you could take advantage of a
compiler's ability to exploit special loop instructions in such a
situation, but it couldn't legally happen by default.

>Is it better to combine all these messages or send out a couple short ones?

If they pertain to separate issues, they are better off in separate
messages, but for many of us it doesn't matter much.

gwyn@brl-smoke.ARPA (Doug Gwyn ) (01/07/88)

In article <10066@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>The loop will not run at all unless you use a different test.

Oops!  I hadn't even noticed the bug.  My earlier response of course
assumed a test like `i < 100', or else the question was pointless.

ok@quintus.UUCP (Richard A. O'Keefe) (01/08/88)

In article <11145@brl-adm.ARPA>, PEPRBV%CFAAMP.BITNET@husc6.harvard.EDU (Bob Babcock) writes:
> TLIMONCE%DREW.BITNET@CUNYVM.CUNY.EDU asks
> >>Question: Under ANSI C,
> >>                    for (i = 0; i == 100; i++) foo(&i);
> >>If foo() does something like: "*i = 0" will this loop ever complete?
> >>I hope this is classified as undefined.
> 
> Seems to me that this is well defined,  and the loop should never
> terminate.   But I'm not sure that the answer doesn't change if i
> is declared noalias.

I thought a loop like this was supposed to be equivalent to
    {
	i = 0;
	while (i == 100) {
	    foo(&i);
	    i++;
	}
    }
Since 0 != 100, the body of the loop should never be executed, so it
had *better* terminate!

Just to keep the 'noalias' pot boiling,
    I asked what makes C so special that it needs 'noalias' when Fortran
    doesn't, and someone said "Pointers!".
Unfortunately, that is not an adequate answer.  It has been known for a
long time that pointers and array elements cause exactly the same problems
with respect to aliasing.  (For example, a Euclid program is, strictly
speaking, legal only if the I =\= J verification conditions the compiler
generates to express "no aliasing through array indices" are provable.)
What I mean by this is that if we have

	float a[1000];

	float fred(int i, int j)
	    {
		float x;
		x = a[i];
		a[j] -= 1.0;
		return x + a[i];
	    }

Is it safe to translate the last expression as x+x?  Only if i != j.
Ok, this is a contrived example, but the opportunity arises again and
again in typical numerical code.  (It is a really big problem for
vectorising compilers.)  So tell me, how do I use the 'noalias'
directive to tell a C compiler it is safe to assume i != j here?
And if 'noalias' cannot be used to tell the compiler that there is no
aliasing here, what good is it?