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

Quick Compiler Question

Name: Anonymous 2010-02-27 9:06

So I was thinking about C programs a short while ago, and a problem occurred to me.

Let's say that I have a function in which, say, we define a variable. It might look something like this:

int dicks (int cocks)
{
    int wangs;
    /* Do stuff to wangs and cocks here */
    return wangs;
}


Looking at int wangs; it seems that the compiler translates that line into "allocate space for an integer and return a pointer to it." If this is a case, is the compiler setting aside space for a new integer every time I run the function, or does it optimize by assuming that I'm only going to have one instance of it and just set aside space for a single int?

Whatever the answer to that previous question is, how would the compiler handle a recursive function? How would


Never mind, I'm an idiot. I forgot about registers and the stack for a second. I revoke my previous questions.

NEW QUESTION: What is the point of tail-call optimization? If all it does is convert recursive functions into iterative ones, why not just program them that way in the first place?

Name: Anonymous 2010-02-27 13:16

I'll need to look at that paper, but I'm not convinced that there are no problems with low-level macros just because you have n namespaces. There is still the issue of shadowing builtins (you can in CL, right?), and other functions and the CL solution seems to be "don't do it, bad little lisper".
You can achieve hygiene with gensyms and symbol-macros1. As for shadowing built-ins, that can only happen if the user explicitly wants to do that (and that would be an error, unless you shadow the symbols in the package via defpackage or shadow): so you could only shadow a built-in, if you're explicitly trying to cause the macro to bind said built-in function or macro via flet/labels/macrolet.

btw, what is the equivalent of make-variable-transformer in CL? It allows for identifers that may or may not be in the CAR position to be macros.

You have symbol macros (define-symbol-macro (global), symbol-macrolet (local)) which let you expand symbols to random expressions, and normal macros for identifiers in the CAR position.


---
1 - http://p-cos.net/documents/hygiene.pdf

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