[ldns-users] Missing or incorrect prototypes

Tony Finch dot at dotat.at
Wed Apr 10 10:00:27 UTC 2013


Dag-Erling Smørgrav <des at des.no> wrote:
>
> BTW, including argument names in prototypes is a bad habit - it pollutes
> the application namespace.

It mostly does not, because function prototype parameter lists are a
distinct scope. The most tricky aspect of identifiers in function
prototypes is that if you declare

  int foo(struct sockaddr_in *sin);

and struct sockaddr_in is not already declared, then the scope of the
struct sockaddr_in is just the function prototype, and is a different type
from every other struct sockaddr_in in the program.

Parameter names are not problematic provided they don't clash with macros.
Functions in the standard library can also have macro versions, which is
generally not a problem since the macro will only be expanded if it is
followed by an open round bracket. However it can cause amusement if you
try declaring function pointer paramaters like

  int abstract_io_thing(int getc(io_handle), void putc(io_handle, int));


ISO 9899:1999 section 6.2.1 Scopes of identifiers:

3 A label name is the only kind of identifier that has function scope. It
  can be used (in a goto statement) anywhere in the function in which it
  appears, and is declared implicitly by its syntactic appearance
  (followed by a : and a statement).

4 Every other identifier has scope determined by the placement of its
  declaration (in a declarator or type specifier). If the declarator or
  type specifier that declares the identifier appears outside of any block
  or list of parameters, the identifier has file scope, which terminates
  at the end of the translation unit. If the declarator or type specifier
  that declares the identifier appears inside a block or within the list
  of parameter declarations in a function definition, the identifier has
  block scope, which terminates at the end of the associated block. If the
  declarator or type specifier that declares the identifier appears within
  the list of parameter declarations in a function prototype (not part of
  a function definition), the identifier has function prototype scope,
  which terminates at the end of the function declarator. If an identifier
  designates two different entities in the same name space, the scopes
  might overlap. If so, the scope of one entity (the inner scope) will be
  a strict subset of the scope of the other entity (the outer scope).
  Within the inner scope, the identifier designates the entity declared in
  the inner scope; the entity declared in the outer scope is hidden (and
  not visible) within the inner scope.

Tony.
-- 
f.anthony.n.finch  <dot at dotat.at>  http://dotat.at/
Forties, Cromarty: East, veering southeast, 4 or 5, occasionally 6 at first.
Rough, becoming slight or moderate. Showers, rain at first. Moderate or good,
occasionally poor at first.


More information about the ldns-users mailing list