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

Pages: 1-

Sepples quiz

Name: Anonymous 2012-08-31 23:49

What does it output?

using namespace std;
#include <iostream>
int main() {
    try {
        void *(*fp)(const int * const);
        throw fp;
    }
    catch(void *(*e)(int *)) {
        cout << "A" << endl;
    }
    catch(void *(*e)(int * const)) {
        cout << "B" << endl;
    }
    catch(void *(*e)(const int *)) {
        cout << "C" << endl;
    }
    catch(void *(*e)(const int * const)) {
        cout << "D" << endl;
    }
    return 0;
}

Name: Anonymous 2012-08-31 23:50

garbage in, garbage out.

Name: Anonymous 2012-08-31 23:50

Lambda Ulrichdrepperuless

Name: Anonymous 2012-09-01 0:03

At first i thought it would be A because it's the most generic function and it has a compatibile-looking signature but then i ran it and it was C because there's no implicit dropping of the const qualifier

The red herring here is that post-declaration const is pretty meaningless outside of member functions afaict

Name: Anonymous 2012-09-01 0:05

>>4
Sturm Mabie doesn't like Ulrich Drepper, does he?

Name: Anonymous 2012-09-01 0:27

>>4
Yay! You've lost your Google job. Should have rote memorized the ISO.

Name: Anonymous 2012-09-01 0:40

Now Sturmy Smabie Smabie Smabie is a Drepper Drepper Drepper

size_t strlcpy(char *to, const char *from, size_t size)
{
        const char *save = from;

        for (size--; (*to = *from++) != '\0'; to += !!size, size -= !!size)
                ;
        return from - save - 1;
}

Name: Anonymous 2012-09-01 0:59

>>7
I remember when I used to write code like this.

Name: Anonymous 2012-09-01 3:51

>>8
How do you write code now?

Name: Anonymous 2012-09-01 3:54

>>9
He probably uses Lisp now, like all reasonable persons.

Name: Anonymous 2012-09-01 4:49

>>9
I generally try to write it in a way so that it will:

* work the first time I write it,
* continue to work after writing lots of other things that affect it and are affected by it,
* be portable across the various compilers,
* be readable for myself and (most) others
* achieve the theoretical asymptotic bounds for memory use and time.
* achieve reasonable constants for memory and time in reference to the above,
* for each component to have a specific and proven necessary purpose

and I used to code like:

* hey lets see if I can make this hash by chaining algorithm all fit inside of a single for loop heading with an empty body.

>>10
I code in lisp in my head but then I compile it to C and C++ as I type.

Name: Anonymous 2012-09-01 6:20

>>11
Let's see your implementation of strlcpy!

Name: Anonymous 2012-09-01 6:53

>>12
/*    $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $    */

/*
 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
#ifndef lint
static const char rcsid[] =
  "$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.2.4.1 2001/07/09 23:30:06 obrien Exp $";
#endif

#include <sys/types.h>
#include <string.h>

/*
 * Copy src to string dst of size siz.  At most siz-1 characters
 * will be copied.  Always NUL terminates (unless siz == 0).
 * Returns strlen(src); if retval >= siz, truncation occurred.
 */
size_t strlcpy(dst, src, siz)
    char *dst;
    const char *src;
    size_t siz;
{
    register char *d = dst;
    register const char *s = src;
    register size_t n = siz;

    /* Copy as many bytes as will fit */
    if (n != 0 && --n != 0) {
        do {
            if ((*d++ = *s++) == 0)
                break;
        } while (--n != 0);
    }

    /* Not enough room in dst, add NUL and traverse rest of src */
    if (n == 0) {
        if (siz != 0)
            *d = '\0';        /* NUL-terminate dst */
        while (*s++)
            ;
    }

    return(s - src - 1);    /* count does not include NUL */
}

Name: Anonymous 2012-09-01 7:08

>>13
daz for noobs

Name: Anonymous 2012-09-01 7:13

>>14
Han's eraser, Ulrich Drepper, Theo the rat, they're all crazy.

Name: Anonymous 2012-09-01 7:31

>13


static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $";


This is undefined behavior, no matter how many checks you write

Name: Anonymous 2012-09-01 7:31

It copies char-by-char?

Wouldn't copying int64-by-int64 be faster if the size is known, or even something like the Duff's Device?

Name: Anonymous 2012-09-01 7:35

>>16
0/10, try again.

Name: Anonymous 2012-09-01 8:19

I got the question in >>1 correct. What do I win?

Name: Anonymous 2012-09-01 11:04

>>17
You should copy int by int, or long int for future proofing.

Name: Anonymous 2012-09-01 11:06

>>17
U MENA rep movsb

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