[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Nested functions
From: |
Zdenek Pavlas |
Subject: |
Re: [Tinycc-devel] Nested functions |
Date: |
Fri, 14 Sep 2007 10:59:59 +0200 |
User-agent: |
Thunderbird 1.5.0.12 (X11/20070530) |
Anton wrote:
Have been lookng over this great discussion about nested
functions and now I am interested: What are the arguments
agains nested procedures/functions, except the difficulties
in implementation and speed issues?
1. Portability issues. Your code now requires compliant compiler and
runtime.
2. Security. There was a strong rationale to make stack not
executable. Nested functions make it even worse than before: not only
is stack executable, but if there is a buffer overflow when the nested
function is in scope, the attacker knows that a fixed `esp + const` is
getting to be called, and very easily exploit that.
Speed is not an issue. The GCC implementation is pretty fast. Actually
I think it's a well designed feature. Very intuitive and sometimes
usefull. But IMHO just not worth the pain.
PS: Why didn't they came a bit farther in syntax, allowing anonymous
local functions and turning them to function pointers. That sould be
easy. Think of:
void for_each(struct list *head, void (*callback)(struct item *item));
struct list *h;
..
for_each(h, void(struct item *i) { printf("item %p\n", i); });
or even better, ala Ruby:
for_each(h) void(struct item *i) {
printf("item %p\n", i);
}
--
Zdenek Pavlas