Name: Anonymous 2015-09-08 21:42
The next time I hear some idiot say ``an array is just a pointer'' I'm going to write an OS in Haskell and remotely install it on their computer.
The solution constituted the crucial jump in the evolutionary chain between typeless BCPL and typed C. It eliminated the materialization of the pointer in storage, and instead caused the creation of the pointer when the array name is mentioned in an expression. The rule, which survives in today's C, is that values of array type are converted, when they appear in expressions, into pointers to the first of the objects making up the array.
/*
* A mention of an array is turned into
* a pointer to the base of the array.
*/
struct tnode *
disarray(ap)
struct tnode *ap;
{
register int t;
register struct tnode *p;
p = ap;
/* check array & not MOS and not typer */
if (((t = p->type)&XTYPE)!=ARRAY || p->op==NAME&&p->tr1->hclass==MOS
|| p->op==ETYPE)
return(p);
p->subsp++;
*cp++ = p;
setype(p, decref(t), p);
build(AMPER);
return(*--cp);
}
Which is essentially what continuations are--GotoStatement?s that are "cleaner" with regard to the underlying machine (goto statements where the label can be saved in a variable).
Reality is like that. You can't always like it, but it catches onto you
As for writing an OS in Haskell - a clue to you: operating systems have something called side effects, all sorts of them, at all times - Haskell tries to wish away side effects and pretend they can be magically isolated (out of site, out of mind) when obviously this is not the case. Imagine a file system that has no side effects (sorry user, you can't save your file to your hard disk - we don't allow side effects
goto doesn't have any theoryThis is the kind of ignorant motherfucker who gets a CS degree these days.
Any advice on selling a rewrite and/or challenges as one nears 1B daily queries for which Haskell would be uniquely advantageous?
The point about call/cc is that it is not a static (lexical) goto instruction but a dynamic oneThose are usually called exceptions (but not the only kind of exception).
sizeof arr
and &arr
? sizeof/alignof
, and address of). Instead we operate on it through pointers, and the compiler makes this convenient to do. But the array type is not the object, the pointer to the first element is not the object and the identifier is still not the object.ptr[5]
means to read data at an offset of 5 * (sizeof whatever data type the pointer is using) from the pointer itself.int * getarray(void) {
int a[5];
return a;
}
int * getarray(void) {
int * a = alloca(5 * sizeof (int));
return a;
}
int * getarray(void) {
int a * = malloc(5 * sizeof (int));
return a;
}
I presume that's also a GCC-specific feature?It's a GNU extension, so not part of any C standard. TCC supports it as well, but most C compilers do not. And the standard switch statement can be considered a form of computed goto.
TCO transforms it into a loop, which is implemented in machine code with a jump or branch instruction, which is the same as a GOTO.
Tail recursion can work with the new parameter values in-place.which is a poor implementation