Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!news.funet.fi!fuug!clinet!dix From: dix@clinet.fi (Risto Kaivola) Newsgroups: comp.sys.amiga.programmer Subject: Re: 4 bytes to a long? Message-ID: <1991Jun13.071938.24742@clinet.fi> Date: 13 Jun 91 07:19:38 GMT References: <55908@nigel.ee.udel.edu> <19488689.ARN0eac@swinjm.UUCP> <1991Jun12.144601.4340@ira.uka.de> Organization: City Lines Oy, Helsinki, Finland Lines: 52 S_ASCHMIDT@iravcl.ira.uka.de (|S| Angela Schmidt) writes: >In <19488689.ARN0eac@swinjm.UUCP> forgeas@swinjm.UUCP writes: >> In article <55908@nigel.ee.udel.edu>, jleonard@pica.army.mil writes: >> >> > mrimages@beach.gal.utexas.edu in <451.28517f01@beach.gal.utexas.edu> write: >> > Is there a fast, simple way to convert 4 bytes into a long? >> > >> > I use : >> > >> > char ch[4]; >> > long l; >> > >> > memcpy( (char *)&l, ch, sizeof(long)); >> >> To convert four bytes into a long: >> l = *((long*) ch) >> This will generate only one instruction: >> move.l _ch,_l >> -- >Oh no! Please don't do this!!!! What will happen if the field of characters >begins at an odd address? The 68020 and higher will do this. But all others >will crash. The chance that the machine survives is about 50% only. Please, >please don't use this conversion!!! I was just wondering, but shouldn't a correct 68000 C compiler generate non-breaking code even in this case? It seems to me that there is just a character pointer to long pointer conversion going on here, which, if I know anything about standard C, should be perfectly legal. That is, in case a data object starts at an odd address, and this object is to be accessed by means of a long pointer, a standard C compiler that is in an environment which doesn't let the processor do long integer access at an odd address, should generate code that accesses the element by means of two or more accesses to smaller entities. No? Does the ANSI standard state that this is implementation-defined, then? >> \___/ >> Jean-Michel Forgeas \-/ >> cbmvax!cbmehq!cbmfra!swinjm!forgeas | The Software Winery >> -^- >> And, where is the universe ? >---------------------------------------------------------+--------------------- >Angela Schmidt Internet: S_ASchmidt@iravcl.ira.uka.de | // >(Nessy in IRC) BITNET: UK8B@DKAUNI2.BITNET | Amiga // > Phone: +49 731 712316 & 721 6904-263 | \\ // only 1000 > MEZ: (10am-9pm) (12pm-10pm) | \X/ the real one! >---------------------------------------------------------+--------------------- -- Risto Kaivola (dix@clinet.fi) or (Risto.Kaivola@f123.n220.z2.FIDONET.ORG)