Google Groups Home
Help | Sign in
Message from discussion Explanation, please!
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Doug Gwyn  
View profile
 More options Aug 25 1988, 12:16 pm
Newsgroups: comp.lang.c
From: g...@smoke.ARPA (Doug Gwyn )
Date: 25 Aug 88 16:16:29 GMT
Local: Thurs, Aug 25 1988 12:16 pm
Subject: Re: Explanation, please!
In article <6...@paris.ICS.UCI.EDU> schm...@bonnie.ics.uci.edu (Douglas C. Schmidt) writes:
-   switch(count % 8) {
-      case 0:  do { *to++ = *from++;
-      case 7:       *to++ = *from++;
-      case 6:       *to++ = *from++;
-      case 5:       *to++ = *from++;
-      case 4:       *to++ = *from++;
-      case 3:       *to++ = *from++;
-      case 2:       *to++ = *from++;
-      case 1:       *to++ = *from++;
-               } while (--n > 0);
-   }

-Now, much to my surprise, this is not only valid C++, it is also valid C!
-Could some one please explain to me why this is so?

Could you explain why it shouldn't be?  "case" labels are just a
special form of label.  You can stick a label on most statements.

-It seems like the case 7-1 labels are actually nested inside the
-do {} while loop, and thus not in the scope of the switch

?? "Thus"?  Why would the labels go out of scope?  They're
definitely within the body of the switch.

-(should a break statement exit both the switch and the loop, or just one?!?!)

A "break" applies to whatever the innermost container is.  A "break"
between two of the "*to++ = *from++;" statements would exit the
do-while loop.

-Finally, Stroustrup asks the rhetorical question ``why would anyone
-want to write something like this.''  Any guesses?!

It's about the fastest way to move arbitrarily-aligned data in
portable C with a guarantee as to what happens in the case that the
data overlaps.  memcpy() doesn't guarantee anything for overlaps.
memmove() does, but that's a recent X3J11 invention that probably
doesn't exist on your system yet.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google