Python Front-end to GCC

Dave Angel davea at davea.name
Tue Oct 22 10:04:57 EDT 2013


On 22/10/2013 08:00, Steven D'Aprano wrote:

> On Tue, 22 Oct 2013 10:14:16 +0100, Oscar Benjamin wrote:
>
   <snip>
> Here's an example: responding to a benchmark showing a Haskell compiler 
> generating faster code than a C compiler, somebody re-wrote the C code 
> and got the opposite result:
>
> http://jacquesmattheij.com/when-haskell-is-not-faster-than-c
>
> Again, I can't judge the validity of all of the changes he made, but one 
> stood out like a sore thumb:
>
>     [quote]
>     C does not require you to set static global arrays to ‘0’, so the 
>     for loop in the main function can go...
>
> Wait a minute... Haskell, I'm pretty sure, zeroes memory. C doesn't. So 

Static int variables are in fact zeroed.  However, most C compilers do
it by putting four bytes (or whatever) into the image of the
executable so it has no runtime cost.

<snip>
> But eventually[1] you will need to fix the security
> vulnerability by adding code to zero the memory, exactly as Haskell and 
> other more secure languages already do. So *not* zeroing the memory is
> cheating. It's not something you'd do in real code, not if you care
> about security and correctness.

I agree with most of what you say in the message, but here you go on to
say the C code is unsafely skipping initialization, which is not the
case.

By the way, a C compiler typically handles any initialization of a
static variable the same way.  So if you declare and initialize a static
variable as

int  myvar = 34 * 768;

it'll put the product directly in the executable image, and no runtime
code is generated.

Perhaps you were thinking of an automatic variable, which is not
initialized unless the programmer says so, and is then initialized with
code.

-- 
DaveA





More information about the Python-list mailing list