From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10f6aa,76b1fcc14e8dced X-Google-Attributes: gid10f6aa,public X-Google-Thread: 1014db,8b6c45fbebd7d3b7 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,c9c309a1859318a1 X-Google-Attributes: gid103376,public X-Google-Thread: 114917,76b1fcc14e8dced X-Google-Attributes: gid114917,public X-Google-Thread: 109fba,76b1fcc14e8dced X-Google-Attributes: gid109fba,public From: abowers@gate.net (Al Bowers) Subject: Re: HELP ! need to insert value in array !! Date: 1997/07/01 Message-ID: <33b7e507.23664154@news.gate.net>#1/1 X-Deja-AN: 253821648 References: <33A9C27C.22F7@post4.tele.dk> <5oci49$97g@crl.crl.com> <866920621snz@genesis.demon.co.uk> <5p0v7l$9uc@nntp.seflin.org> <33b64c2f.43589878@nntp.ix.netcom.com> <33b67602.54296884@nntp.ix.netcom.com> Organization: CyberGate, Inc. Newsgroups: comp.lang.c,comp.lang.c++,comp.os.msdos.programmer,comp.lang.asm.x86,comp.lang.ada Date: 1997-07-01T00:00:00+00:00 List-Id: 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 > > 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 #include /* 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