Berkeley CSUA MOTD:Entry 20435
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

2001/1/25-27 [Uncategorized/Profanity, Computer/SW/Compilers] UID:20435 Activity:very high
1/25    Which is a more efficient strcpy()?  Is it copying each character
        until you reach \0; or is it calling strlen() to get the length
        of the string and executing a memcpy of that length?
        \_ That probably depends on the CPU architecture, e.g. whether or not
           it has string instructions and how efficient they are.
           \_ Assume Pentium 3 with a Linux 2.x kernel and using gcc 2.95.2.
              \_ with strlen() counting each character until \0 is found.  :-)
                 \_ why?
                    \_ Relax, son, it's a joke.  Move along.
        \_ wc `locate strcpy.c bcopy.c`
        50     337    2163 /usr/src/lib/libc/string/strcpy.c
        47     328    2085 /usr/src/sys/libkern/strcpy.c
        35     112     711 /usr/src/contrib/binutils/libiberty/bcopy.c
       139     685    4175 /usr/src/lib/libc/string/bcopy.c
       271    1462    9134 total

            #include <string.h>

            char *
            strcpy(to, from)
                    register char *to;
                    register const char *from;
            {
                    char *save = to;

                    for (; (*to = *from) != 0; ++from, ++to);
                    \_ != 0 not needed
                    return(save);
            }
                \_ Now do it in 6052, 80286, perl 4.036 (1 line or less),
                   and 3 other languages/scripts of your choice.
                   \_ by "6052" do you mean 6502?  fucking hoszer.
                        \_ Holy shit!  A typo!  And you caught it!  Wow!
                           You are *soooo* smart!  Did you tell yermom?
                           I'd bag on _your_ typo but I'm not as smart as you.
                           \_ I'd bag on your misspelling too fag.
                              \_ Uhm, there wasn't one, son....  Either way,
                                 if the best you can do is toss around "fag"
                                 one liners, maybe you're better off just not
                                 bothering.  Maybe you should try again in a
                                 few years when you're passed your 6th grade
                                 tests.
                                 \_ Suck my dick, cocksucker.
        \_ gcc has a built-in implementation of strcpy, but i can't get it
           to emit on linux, gcc 2.95.2. anyone have better results? -ali
           \_ Try compiling with -Dstrcpy=__builtin_strcpy. The -fhosted or
              -fbuiltin options sound like they should work, but they
              don't. -asaddi