HackerTrans
TopNewTrendsCommentsPastAskShowJobs

david-given

no profile record

comments

david-given
·10 years ago·discuss
That's correct --- the standard doesn't say anything about raw memory. Only pointers to objects defined by C are defined to work; everything else is an implementation-specific extension (and so, covered under 'undefined behaviour').

I believe that C99 added the ability to losslessly cast from a pointer to a uintptr_t and back again, but, IIRC, the compiler didn't have to support this in C89.
david-given
·10 years ago·discuss
The standard doesn't even guarantee that pointer arithmetic works at all, outside the bounds of an object (or at least did in C89, which is the only standard I know well).

If you have an object which is ten bytes long, like:

    uint8_t o[10];
...then it's legal to construct pointers to o[0] through o[10] --- not o[9]; you can create a pointer to the byte immediately after the object --- and nowhere else. Like, it's not even legal to calculate one, let alone dereference it.

I used this to make a prototype compiler from C to Javascript/Perl/Lua, where each C pointer was represented as a tuple of (array, offset). Pointer arithmetic worked inside objects; pointer arithmetic between objects wasn't supported. Worked nicely.
david-given
·10 years ago·discuss
gcc nested functions do have access to their parent's variables. Obviously only until the parent exits --- they're not closures.

I would love for this to be in the standard, particularly if they come up with a nested function literal syntax. Having them would make things like mutation callbacks and foreach() so much cleaner.
david-given
·10 years ago·discuss
The BBC Micro also allows you to change the address of the video framebuffer. A particularly neat trick was to remap it to 0x0000, so you get to see the OS workspace, stacks, program storage etc. You can watch the bits twiddle in realtime as you do things.

There's another neat hack which would cause the machine to run in slow motion. I don't know how it worked; I can't find any references now. Possibly it overloads the system with interrupts. But under its influence, clearing the screen would take several seconds. These two hacks combined beautifully, letting you see all the details of, e.g., Basic's heap management.
david-given
·11 years ago·discuss
I've heard people say that TeX typesetting is so nice that people will do scientific research just so that they can publish papers using it.
david-given
·11 years ago·discuss
I quite like K&R C --- it has an elegant minimalism to it that was lost in ANSI C:

    add(a, b, c) { return a+b+c; }
But the ad-hoc parameter types only really worked if all your types were the same size, so it doesn't really get on with 64-bit machines. (I have just fixed some ancient code which was doing this:

    msg(s, a1, a2, a3, a4)
        char* s;
    {
        printf("info: ");
        printf(s, a1, a2, a3, a4);
    }

    ...later...
    {
        msg("an int is %d", anInt);
        msg("a string is %s", aString);
    }
Yeah, no.

I don't know classic Algol, but I've dabbled in Algol-68 (a most underrated language), and in that the parameter passing syntax is unrelated. The add function would have looked like:

    proc add = (int a, int b, int c):
        (a + b + c)