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 9:44

>>3
you can do thte same in Scheme, though I don't think they ever had real macros properly standardized, though most implementations support them, and they were defined in the R4RS? appendix as well
What, is syntax-case not real enough for you? It's been around since '92[1] and was standardized in R6RS[2]. It's hygienic by default, but you are allowed to explicitly break hygiene. Having syntax-case also gives you the higher-level macro systems like syntax-rules and extend-syntax for free as they are both about 8 lines of code.

We also have iteration constructs (no really, real ones). First there is the ugly 'do' which you should be familiar with. Also, SRFI 42[3] gives you eager comprehensions and SRFI 41[4] gives you lazy comprehensions. There has been lots of other work on iteration in Scheme, notably Olin Shivers' "Anatomy of a loop"[5] which the bastard hasn't released code for, and Alex Shinn wrote a nice but really long post on c.l.s a few years back[6].

The problem with general iteration, not special cases like comprehensions, is that it is difficult to create a set of iteration constructs that are powerful, that make what you are doing explicit on a high level, and which get the semantics just right. CLs loop macro is a good start, but it's far from perfect and lower level iteration is just as much a chore as writing it out with TCO and recursion

[sub]--
1. Writing hygienic macros in Scheme with syntax-case, http://www.cs.indiana.edu/~dyb/pubs/tr356.pdf
2. Revised[sup]6[/sup Report on the Algorithmic Language Scheme,Standard Libraries, Chapter 12 http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-13.html
3. SRFI 42: Eager Comprehensions, http://srfi.schemers.org/srfi-42/srfi-42.html
4. SRFI 41: Streams, http://srfi.schemers.org/srfi-41/srfi-41.html
5. Anatomy of a Loop, http://www.cc.gatech.edu/~shivers/papers/loop.pdf
6. Yow! LOOP macros are LOOPY! http://groups.google.com/group/comp.lang.scheme/browse_thread/thread/0cb91974bc35a86c/060dcac5ea812398?#060dcac5ea812398[sub]

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