BartC said:
Tim Rentsch said:
`struct structure1'. The functions that the `create' field
can point at will all have the same "signature" -- they'll all
take two `int' arguments and return a `struct structure1 *' --
but they can have any names at all. [snip]
The last sentence is wrong in a couple of different ways. In C
the term is type, not signature; the various target functions
will have the same type (provided they have been suitably
declared, which they may not have been, and indeed they might not
even be written in C; even so the appropriate term is type).
Furthermore, the sentence above misuses the term "signature" to
mean _only_ the type, which isn't how it is generally used.
Different functions, even if they have the same type, will not
have the same 'type signature'
http://en.wikipedia.org/wiki/Type_signature
That article says the signature includes the name of the
function. That's wrong. [snip]
No, it isn't. Try looking up what a signature is in, for
example, the C++ language definition document or the Java
language definition document.
There are two attributes of a function: its signature (the set
of parameters, plus the return type),
Again, this usage is out of step with how the term is used
in languages that have an official definition.
and its type (what value it yields when a call to it is used in
an expression, which is the same as its return type).
And this is wrong for C. In C the type of a function also gives
a specification for the types of the function parameters. That
may be a partial specification rather than a full specification,
but a function type always includes some information about what
parameter typings are allowed.
So signature and type can mean two different things.
They do mean different things, because a signature includes
the name of the function, method, or constructor in question.
Two functions can be compatible if they have the same signature
(you can substitute the name of one, with the name of the other,
and it should still be valid type-wise). And when you have
function pointers, there is no name of the function to consider,
only signature (which in C you might call the 'type' just before
you call it, and then have another type as its result).
In C the type of a function includes both the type of its result
and the types of its parameters. If the distinction is important
we might say "fully specified type" rather than just "type", but
these days developers almost always write function declarations
using prototypes, so in most cases there is no difference. Some
people misuse the term "signature" to mean essentially the same
thing as "fully specified type", but (a) there's no reason to do
so, since "type" or "fully specified type" works just fine, and
(b) the term "signature" is not defined (indeed, the word never
appears) in the Standard, and other languages that use the term
define it differently.
A declaration isn't quite the same as a signature either,
The term "signature" means different things in different languages,
but AFAIAA all languages that use the term (ie, as part of their
official definition) include some kind of name information along
with type information. Furthermore my comment was about the term
"type signature", as explained in the Wikipedia article. That
definition is pretty close to what most languages would call a
declaration, the main differences being (a) declarations often
include some additional keywords or punctuation so that they may be
identified as declarations in the program, and (b) declarations
may be given for both non-functions and functions, whereas "type
signature" applies only to function or function-like entities.
The two terms clearly aren't the same, but there is an obvious
mapping between them which is (for functions) basically an
isomorphism.
but you can define a signature using a declaration.
Here again you're assuming that your personal usage corresponds
to how the term is used in other languages. It doesn't. In C++,
for example, a declaration by itself is not enough to infer a
function signature, which also includes the namespace(s) in which
the function is defined.
It would be like saying a type is the same as a declaration
too.
Only if one mistakenly assumes that the terms "signature" or "type
signature" are basically synonymous with "fully specified type",
which they are not.