New GCC takes 19x as long to compile my program (compared to old GCC), plus void** patch suggestion

David Brown david.brown@hesbynett.no
Wed Aug 8 17:06:00 GMT 2012


On 08/08/12 16:01, Elmar Krieger wrote:
>
> One other thing I just thought of: GCC has a history of very smart
> extensions to C that allow to write faster and more elegant code. If I
> look at my code, there are mostly two sources of 'dirty hacks' left. One
> that could be fixed easily is the 'void** pointer problem', that
> clutters my code with nasty explicit type casts:
>
> A simple example is the function freesetnull, that frees a pointer and
> sets it NULL (ptradd is a pointer address):
>
> void freesetnull(void **ptradd)
> { free(*ptradd);
> *ptradd=NULL; }
>

I suspect this should be on the gcc-help mailing list rather than the 
development list.  But since you asked here, I'll try to help here.


Normally, good style encourages using static inline functions instead of 
macros, but here I would go for a macro:

freesetnull(_p) do { free(_p); _p = NULL; } while (0)

Note the slight change in the semantics - you pass the pointer, not a 
pointer to the pointer.

I expect this will also have the bonus of improving the speed of the 
resulting program - and possibly even of the compilation.

What's the other dirty hack?


Regarding compile time, modern gcc has "-funit-at-a-time" and 
"-ftop-level-reorder" enabled by default, even with no optimisation 
enabled.  These could take time on such a huge source code.  Try 
compiling with "-fno-unit-at-a-time" (which implies 
"-fno-toplevel-reorder").

mvh.,

David




More information about the Gcc mailing list