comp.lang.ada
 help / color / mirror / Atom feed
From: abowers@gate.net (Al Bowers)
Subject: Re: HELP ! need to insert value in array !!
Date: 1997/07/01
Date: 1997-07-01T00:00:00+00:00	[thread overview]
Message-ID: <33b7e507.23664154@news.gate.net> (raw)
In-Reply-To: 33b67602.54296884@nntp.ix.netcom.com


On Sun, 29 Jun 1997 15:05:28 GMT, miker3@ix.netcom.com (Mike
Rubenstein) wrote:
Referring to C language , I agree with your arguments. However,
the C code you use to reinforce your argument is faulty.

>It's quite easy to detect the difference.  For example,
>
>	#include <stdio.h>
>
>	int main(void)
>	{
>	  int a[2];
>	  unsigned long d = (char*) a[1] - (char*) a[0];
should be:
               unsigned long d = (char *)&a[1] - (char *)&a[0];
or 
               unsigned long d = (char *)(a+1) - (char *)a;
>	  printf ("%lu %lu\n", d, sizeof(int));
               printf("%lu %lu\n",d,(unsigned long)sizeof(int));
>	  return 0;
>	}
>
>This must print the same number twice.
>
>Note also that without this rule there would be no guarantee that code
>like
>
>	#include <stdlib.h>
#include <string.h> /* for memcpy() */
>
>	int a[5] = { 1, 2, 3, 4, 5 };;
                                                  ^^
>	int *b = malloc(5 * sizeof *b);
>	if (b != NULL)
>	  memcpy(b, a, sizeof a);
>
>would work.  It would be extremely difficult for an implementation to
>fake this with non-contiguous arrays since the ultimate type of the
>allocated memory may not be known at the time the malloc() is done.
>
>From ISO 6.1.2.5:
>
>	An array type describes a contiguously allocated nonempty set 
>	of objects ...

Al Bowers                                
Tampa, FL
mailto:abowers@combase.com
http://www.gate.net/~abowers/index.html




  parent reply	other threads:[~1997-07-01  0:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <33A9C27C.22F7@post4.tele.dk>
     [not found] ` <5oci49$97g@crl.crl.com>
     [not found]   ` <866920621snz@genesis.demon.co.uk>
1997-06-27  0:00     ` HELP ! need to insert value in array !! Ralph Silverman
1997-06-28  0:00       ` Lawrence Kirby
     [not found]       ` <dewar.867554609@merv>
1997-06-29  0:00         ` Mike Rubenstein
1997-06-29  0:00           ` Robert Dewar
1997-06-29  0:00             ` Mike Rubenstein
1997-06-29  0:00               ` Robert Dewar
1997-06-29  0:00                 ` Mike Rubenstein
1997-06-30  0:00                 ` Ed Hook
1997-07-04  0:00                 ` Richard A. O'Keefe
1997-07-07  0:00                   ` Clive D.W. Feather
1997-07-01  0:00               ` Al Bowers [this message]
1997-07-01  0:00             ` Richard Kenner
1997-07-01  0:00               ` Robert Dewar
1997-07-02  0:00             ` Christian Froeschlin
1997-07-02  0:00               ` Robert Dewar
1997-07-04  0:00             ` Richard A. O'Keefe
1997-07-04  0:00               ` Robert Dewar
1997-07-04  0:00                 ` Mike Rubenstein
1997-07-05  0:00                   ` Robert Dewar
1997-07-05  0:00                     ` Larry Kilgallen
1997-07-05  0:00                     ` Mike Rubenstein
1997-07-05  0:00                       ` Mike Rubenstein
1997-07-10  0:00                     ` Alan Bowler
1997-07-07  0:00                 ` Shmuel (Seymour J.) Metz
1997-07-07  0:00                 ` Mark H. Wood
1997-07-09  0:00                   ` Robert Dewar
1997-07-10  0:00                     ` Lawrence Kirby
1997-07-08  0:00                 ` Richard Kenner
1997-06-30  0:00         ` Samuel T. Harris
replies disabled

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