| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: C++ for beginners? |
From: "Paul Ranson"
The built in operator '^' is only defined for integer types. But a string
or complex implementation could provide it itself. So Tony's code could
complile, but would obviously be unlikely to work.
Paul
"John Beckett" wrote in
message news:h2n2q0h6o30p2o6ahtj1b43gbi3ttnbgqf{at}4ax.com...
> On Sun, 21 Nov 2004 19:13:19 -0500, "Geo"
wrote:
>>Why wouldn't it work for strings? Strings are just arrays of characters
>>and
>>a character is simply a value like an int is a value.
>
> I hope you realise that Tony's suggestion:
> x ^= y ^= x ^= y;
> was very tongue-in-cheek.
>
> It is old folk lore that this magnificent code will swap the contents
> of x and y, and programmers talk of days when such tricks were needed
> to minimise use of data memory (particularly stack memory), at the
> expense of code memory.
>
> I'm not sure whether anyone ever actually needed to use this code.
>
> The ^ (bitwise xor) operator is only defined for integer variables. It
> is probably illegal (compiler error) with float or string.
>
> The trick (if not illegal) would have to fail for strings because the
> code operates on the contents of x and y. For a string, the "contents"
> would actually be an address that points to some data structure
> holding the actual string.
>
> You could argue that a more clever language would know that the TRUE
> contents of a string was the actual characters, but C/C++ is not like
> that. Xor is supported in so far as the CPU supports it.
>
> John
>
--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)SEEN-BY: 633/267 270 5030/786 @PATH: 379/45 1 396/45 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.