Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

HAY GUYS WUT DO U THINK OF THIS

Name: Anonymous 2006-06-28 18:47


"On Wednesday, June 28, 2006 you asked the following question;

this loop:

while(*(string1++)=*(string2++));

when does it ends?

The following answer has just been sent to you;

It doesn't if this is in C++. You assigned string2 to string1. == is for comparisons. fuckin' n00b."

i lold

Name: Anonymous 2006-06-28 19:04

I think he's right.  Desu.

Name: Anonymous 2006-06-28 19:27

have you tried to implement it?

Name: Anonymous 2006-06-28 19:30

>>1
its an implementation of the strcpy() function

Name: Anonymous 2006-06-28 19:58

Assignment operators with return values: Good or bad idea?

Discuss.

Name: Anonymous 2006-06-28 20:00

He/she's right 255 times out of 256.

Name: Anonymous 2006-06-28 20:15

i also loleth

Name: Anonymous 2006-06-28 21:48

>>5
Good idea. What are you going to use, an if-else? Oh plz :)

Name: Anonymous 2006-06-29 0:37

>>5
Good. Makes for more succinct code when you need to check return value of something and save it too...

Name: Anonymous 2006-06-29 3:39

>>5
Awesome idea, every language should do this.

Name: Anonymous 2006-06-29 13:42

i rofled

Name: Anonymous 2006-07-06 7:20 (sage)

i zomg'ed

Name: Anonymous 2006-07-24 1:47

>>1


didnt get it, someone explain it plz?

Name: Anonymous 2006-07-24 9:09

>>13
take a pen, a paper and do it yourself.

Name: Anonymous 2006-07-24 10:36

>>13
It copies string 2 into string 1 until it reaches the null terminator, because then the return value of the expression will be 0, or false.

Name: Anonymous 2006-07-24 18:26

i kekkled

Name: Anonymous 2006-07-25 19:48

>>15
pointlessly esoteric way to do that....

Name: Anonymous 2006-07-25 19:50

>>17
Stupid anonymous!  C++ is not a food!

Name: Anonymous 2006-07-25 21:34

>>17
Except for the fact that it's efficient, bitch.

Name: Anonymous 2006-07-25 21:44

>>19
How is it efficient?
Size, sure, sort of. Speed, not really.

Name: Anonymous 2006-07-26 0:06

>>20 Speed, not really.
?!?
Fine, you write something in C that's faster.

Name: Anonymous 2006-07-26 0:33

This is a classic example of
(a) Why C is a bad language.
(b) Why C is a good language.

If you haven't seen this before, you're probably still pretty newbish to the language.

As for >>19, Most modern compilers will produce code that is at least as fast, if not faster, from more readable code.  That's the way the optimizations are tuned.  I recall, a few years ago, a prof I was TAing for using this as an example for his class to show how premature optimization can bite you in the ass.  He wrote and instrumented two string copies, this obfuscated one and a much more mundane, readable version.  He ran them both in class, for the class, and showed the class the performance numbers.  The readable version was faster.

Why?  Who knows.  Could be instruction cache misses, misaligned CPU cache lines, or any one of a hundred other things.  The point is, you can't know until you measure.

So never forget:  Terseness != Optimized for Speed.  There are waaaaay too many things going on in the background to make a snap judgement like that without measuring.

Name: Anonymous 2006-07-26 0:36

Isn't that a bug as written?  Shouldn't it be

while(*dest++=*src++);

?

After all, you don't want to increment your pointer before you dereference and make your first character copy, which is what the current parentheses will do.  Same reason that

while(*++dest=*++src);

is wrong.

Name: Anonymous 2006-07-26 0:40

>>5

Good idea.  If the assignment didn't return anything, you couldn't chain them like so:

int a, b, c;
a = b = c = 0;

Long live the returned reference.

Name: Anonymous 2006-07-26 6:29 (sage)

>>23
Postfix ++ may increase the pointer, but its return value is the pointer before the increment.

>>21
On a 32-bit processor, copying words/dwords is usually faster than copying separate bytes.

>>24
Problem is that you have to read that right-to-left (counter to the rest of the program). Something like 0→a→b→c might make more sense.

Name: Anonymous 2006-07-26 8:28

>>25
>Problem is that you have to read that right-to-left (counter to the rest of the program)

Fuck are you talking about? It's no different than chaining functions: a(b(c(0)))

Name: Anonymous 2006-07-26 10:01 (sage)

>>26
Yeah, you're right, I should've said operators instead of program (and even then the execution order is usually more dependent on precedence rules).

Name: Anonymous 2006-07-27 0:47

>>25

You're saying that

*(p++)

is functionally equivalent to

*p++

?

I guess I need to review the precedence rules re: the postincrement and dereferencing operator, then, because that doesn't seem right to me.  I would expect the parentheses to force the postincrement to evaluate before we evaluate anything surrounding the parentheses, including the *.

Problem is that you have to read that right-to-left (counter to the rest of the program). Something like 0→a→b→c might make more sense.

Who says that's a problem?  Standard mathematical assignment notation has always been intuitively right-associative to me.  This is a personal preference thing, not an objective fault in the approach.

Name: Anonymous 2006-07-27 9:25

>>28
I would expect the parentheses to force the postincrement to evaluate before we evaluate anything surrounding the parentheses
Exactly. And the return value of that evaluation is the original pointer, so it doesn't matter if it was incremented. That's the mayor difference between (++x) and (x++), the former evaluates to the incremented pointer, the latter to the original pointer (although it still gets incremented).

Name: Anonymous 2006-07-27 19:54 (sage)

Wow, discussing basic stuff that you should've learned in an intro course is fun.

Name: Anonymous 2006-07-29 7:06

I learned about that version of the strcpy function in 9th grade, lol

I went to a school that was running linux in a computer class in 1998 :)

True story.

Name: Anonymous 2006-07-29 12:37 (sage)

>>31

protip: no one gives a fuck about you

Name: Anonymous 2006-07-29 13:52 (sage)

>>31
Wow, you're pretty cool Anonymous.

Name: Anonymous 2007-07-05 7:09 ID:0QhK5LUk

string2 has to be null terminated. duh.

Name: Anonymous 2007-07-05 7:32 ID:9wRFE/Qr

>>34
Bumping faggot

Name: Anonymous 2007-07-05 10:57 ID:IwLHL4Rf

>>34
you either get a memory error or it'll stop somewhere even outside of the string


char tmp[4];
char str[] = { 'a', 'b', 'c' };
int n = 0;
strcpy(tmp, str); /* stops at &n */
puts(tmp);

Name: Anonymous 2010-06-07 6:49

Hi, I can spam /prog/ too, you faggot.

Also, smoke weed everyday.

Name: Anonymous 2010-06-26 9:58

ur gay

Name: Anonymous 2010-11-27 15:07

Name: Anonymous 2010-11-27 19:07

Name: Sgt.Kabu䰘݋kiman�䲖 2012-05-28 19:20

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List