This is the mail archive of the
mailing list for the glibc project.
Re: [WIP] Remove nested function in elf/dl-lookup.c? (Nested functions considered harmful?)
- From: Roland McGrath <roland at hack dot frob dot com>
- To: "Carlos O'Donell" <carlos at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Mon, 16 Dec 2013 12:56:49 -0800 (PST)
- Subject: Re: [WIP] Remove nested function in elf/dl-lookup.c? (Nested functions considered harmful?)
- Authentication-results: sourceware.org; auth=none
- References: <52AC8036 dot 7000300 at redhat dot com>
> Is it me or does reading do_lookup_x get very very complicated
> with the nested function check_match which has access to all
> sorts of function local variables?
> I'm always suspicious of nested functions like this as bad
> programming form since it complicates reading the function.
No, using a nested function like this vastly improves readability.
Having a function with arguments that are just copies of its callers
arguments is error-prone and tedious to read through.
> Is anyone opposed to rewriting this with a non-nested function
> that clearly shows which arguments are constant, and which are
A good way to make that clear is to put the definition of the nested
function earlier in the scope, where only the things it uses have been
declared at the definition site.