Subject: Re: libssh2 master 37624b6 sftp_attrsize: converted function to a macro

Re: libssh2 master 37624b6 sftp_attrsize: converted function to a macro

From: Simon Josefsson <>
Date: Wed, 28 Apr 2010 08:42:52 +0200

Alexander Lamaison <> writes:

> wrote:
>> sftp_attrsize: converted function to a macro
>> This way, the macro can evaluate a static number at compile time
>> for two out of four uses, and it probably runs faster for the
>> other two cases too.
> Oh please no.
> These kind of hand optimisations are almost always useless. Was there
> any other reason for the conversion except performance? If not, was
> there a benchmark to show this was a bottleneck and the macro fixed
> it?
> Time and time again people try this type of thing without realising
> that compilers and architectures make it almost impossible to predict
> if there is any speedup in practice. Compilers play with your code
> and, more importantly, different processor architectures do strange
> things that make execution bear no resemblance to how you imagined it
> would happen.
> In practice, this may even run slower.

I agree in general -- macros are more difficult to read and debug, and
in my experience almost never results in any noticeable speedup compared
to static functions, and may result in larger code size. Unless we have
benchmarks showing there is a bottleneck (see [1] for an example of
where optimization was warranted, although not related to macros) my
preference would be to use static functions even for trivial operations
that are often written as macros.

(I didn't look at the actual details here though, just speaking


Received on 2010-04-28