neilbrown / wiggle

apply rejected patches and perform word-wise diffs
http://neil.brown.name/wiggle
GNU General Public License v2.0
91 stars 8 forks source link

Remove nested functions for more portable code #2

Closed seanfarley closed 10 years ago

seanfarley commented 10 years ago

Compiling with clang (default on Mac OS X nowadays) threw a bunch of errors since nested functions are a gcc C language extension. -Wno-missing-field-initializers has also been added to the makefile since the line that clang complained about:

vpatch.c:2350:21: error: missing field 'outfile' initializer [-Werror,-Wmissing-field-initializers]
        struct plist p = {0};

is valid C99 and will indeed be zeroed upon initialization.

neilbrown commented 10 years ago

Hi. Thanks for these. I wondered if using local functions might cause a problem for someone....

However I don't want to merge them as they are. For 'free_stuff' I would prefer if the call site still looked like a function call. i.e. it should still be "free_stuff()" everywhere. Also for all of them the standard practice when creating these sorts of macro is to wrap the body in "do {" and "}while(0)", so that a ";" afterwards is syntactically part of the statement. This is import if the macro/function ever call using in a compound statement like "if (...) free_stuff(); else ....". If you could redo that patches with those two changes I'll happily pull them. Thanks, NeilBrown

seanfarley commented 10 years ago

Thanks for the review! I've changed the macros to use 'do … while(0)' now. Let me know if that works for you.

neilbrown commented 10 years ago

Yes, that works for me, thanks.