Newsgroups: alt.lang.design,comp.lang.c++,comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!udel!gatech!swrinde!pipex!uunet!sparky!kwiudl.kwi.com!netcomsv!netcomsv!netcom.com!nagle
From: nagle@netcom.com (John Nagle)
Subject: Re: Comparing productivity: LisP against C++ (was Re: Reference Counting)
Message-ID: <nagleD16D3G.JtE@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
References: <19941203T221402Z.enag@naggum.no> <BUFF.94Dec15103904@pravda.world> <D0xAIp.3Dn@rheged.dircon.co.uk> <vrotneyD11MDv.Ks7@ <19941221.101010.961339.NETNEWS@UICVM.UIC.EDU>
Date: Wed, 21 Dec 1994 19:06:52 GMT
Lines: 28
Xref: glinda.oz.cs.cmu.edu comp.lang.c++:104464 comp.lang.lisp:16140

dhanley@picasso (David Hanley) writes:
>:   for (p = data; p != data + width * height; p++)
>:     *p = 255 - *p;
>: }

>        This could be written *much* faster, to wit:
>int *p, e = ( int * ) ( data + width * height );
>assert( p != NULL ); //Much nicer this way.
>for( p = (int*) data ; p < e ; ++p)
>  *p ^= 0xffffffff;

     That's illegal in C++.  See the ARM, section 5.4.   You can't convert
a "char *" to an "int *".  Some compilers (gcc, for one) allow this, but 
they're wrong.  Symantec C++ 7.0 gets it right:

	Error:   cannot implicitly convert
	from: char *
	to  : int *

Actually, in C++, you can't even convert an "int *" to a "char *".  C
allowed that, but C++ doesn't.  You can force the issue by going through
a "void *", but the resulting pointer may not be valid for dereferencing.
Properly, a "void *" has the alignment restrictions of objects.  Remember,
on many machines, the hardware won't operate on misaligned pointers.

					John Nagle
 

