Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Pointer to function inside struct

Reply
Thread Tools

Pointer to function inside struct

 
 
Tim Rentsch
Guest
Posts: n/a
 
      03-19-2013
Seebs <(E-Mail Removed)> writes:

> On 2013-03-17, Tim Rentsch <(E-Mail Removed)> wrote:
>> 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.

>
> This is interesting. I've often seen "signature" used to refer
> to the function's type, as in "you need a function matching the
> signature of..."


Yes; it is, regrettably, a common misusage.

>> Again, this usage is out of step with how the term is used
>> in languages that have an official definition.

>
> I don't have specs for them, but I am not sure that this is
> persuasive in a discussion of C, and even in C++, I see plenty
> of examples of people using the term in the sense of "type of
> arguments and return".


I see plenty of examples in comp.lang.c where people make
mistaken claims about what ISO C allows or doesn't. That
doesn't mean the claims are right.

Perhaps more to the point, the purpose of my comments is to say
(a) the term "signature" has no official definition in the ISO C
standard, (b) in languages where it does have an official
definition, it means something significantly different from how
people often use it here, (c) it's confusing to use a "common"
term to mean something different from what it officially means,
and (d) as far as C goes there is no reason to do so since C
defines "type" to mean basically the same thing that people mean
when they say "signature". And I think it's a bad idea for
another reason, namely, sloppy language promotes sloppy thinking.
I think it's worthwhile to discourage both. Are these comments
all ones you agree with? If not, with which ones do you not
agree?

> I suspect that what's happened here is that the concept of "a
> signature which is compatible with the signature of X" or
> something similar got compressed and extra words dropped. So
> in practice, it appears that people frequently talk of two
> signatures "matching" even if one or more of the names involved
> are different.


AFAIK the term 'signature' was first used in the programming
language Russell, where it meant something different still, and
certainly did not mean 'type', because Russell also used the term
'type' and that was clearly distinct from signatures (among other
things, types existed at runtime, whereas signatures existed
purely at compile time). (IIRC signatures in Russell were rather
elaborate compound entities, and included names of operations.)

As far as what may have happened, to me it seems more likely
that people picked up the term without really understanding what
it meant in the original context, and started using it without
knowing what it was supposed to mean, because it sounds more
cool and more sophisticated than a short word like type. And
unfortunately that misunderstanding has gotten propogated by the
term being repeated by further people who mimicked what they
heard without bothering to go back and try to find out where
the term may have come from. Sometimes that's good for natural
language; for technical language it usually isn't.
 
Reply With Quote
 
 
 
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      03-20-2013
Tim Rentsch <(E-Mail Removed)> wrote:

(snip)

> AFAIK the term 'signature' was first used in the programming
> language Russell, where it meant something different still, and
> certainly did not mean 'type', because Russell also used the term
> 'type' and that was clearly distinct from signatures (among other
> things, types existed at runtime, whereas signatures existed
> purely at compile time). (IIRC signatures in Russell were rather
> elaborate compound entities, and included names of operations.)


> As far as what may have happened, to me it seems more likely
> that people picked up the term without really understanding what
> it meant in the original context, and started using it without
> knowing what it was supposed to mean, because it sounds more
> cool and more sophisticated than a short word like type. And
> unfortunately that misunderstanding has gotten propogated by the
> term being repeated by further people who mimicked what they
> heard without bothering to go back and try to find out where
> the term may have come from. Sometimes that's good for natural
> language; for technical language it usually isn't.


I suppose, but it seems to me that, at least in some languages,
it is meant to be the unambiguously unique indication of which
routine to call. We also hope that our written signatures
are unambiguously unique, so it makes some sense.

-- glen
 
Reply With Quote
 
 
 
 
Seebs
Guest
Posts: n/a
 
      03-20-2013
On 2013-03-19, Tim Rentsch <(E-Mail Removed)> wrote:
> Seebs <(E-Mail Removed)> writes:
>> On 2013-03-17, Tim Rentsch <(E-Mail Removed)> wrote:
>>> 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.


>> This is interesting. I've often seen "signature" used to refer
>> to the function's type, as in "you need a function matching the
>> signature of..."


> Yes; it is, regrettably, a common misusage.


If it's sufficiently common, I'd argue that the formal definitions are
probably wrong.

> I see plenty of examples in comp.lang.c where people make
> mistaken claims about what ISO C allows or doesn't. That
> doesn't mean the claims are right.


Fair enough...

> Perhaps more to the point, the purpose of my comments is to say
> (a) the term "signature" has no official definition in the ISO C
> standard,


This would argue that no definition of it contradicts the spec.

> (b) in languages where it does have an official
> definition, it means something significantly different from how
> people often use it here,


Is that *always* true or just true of those particular languages?

Come to think of it: I'm pretty sure Haskell uses the distinction that
"type signature" refers to the pattern of types associated with a given
function.

And I've spotted a significant difference, looking at usages in other
languages: A "type signature" may express information which is not really
there in the code. For instance, Lua doesn't really have variable typing
like C does, but an API spec may give information about the types accepted and
returned anyway -- and call that a type signature.

> (c) it's confusing to use a "common"
> term to mean something different from what it officially means,
> and


True, but my view would be that there's no official meaning in C.

> (d) as far as C goes there is no reason to do so since C
> defines "type" to mean basically the same thing that people mean
> when they say "signature".


While this is arguably true, it seems to me that there's a significant
connotational difference here. Connotations aren't always in the formal spec,
but are part of how people keep things disentangled.

*thinks*

Okay, my vague sense of the usage difference: A type is just the pattern of
bits a given thing is using. A signature is a thing you are supposed to match.

> And I think it's a bad idea for
> another reason, namely, sloppy language promotes sloppy thinking.


I mostly agree, but!

It is sometimes a sign that people need more distinctions than the formal
terminology provides.

> As far as what may have happened, to me it seems more likely
> that people picked up the term without really understanding what
> it meant in the original context, and started using it without
> knowing what it was supposed to mean, because it sounds more
> cool and more sophisticated than a short word like type. And
> unfortunately that misunderstanding has gotten propogated by the
> term being repeated by further people who mimicked what they
> heard without bothering to go back and try to find out where
> the term may have come from. Sometimes that's good for natural
> language; for technical language it usually isn't.


I have this vague recollection of seeing the term pretty early on in C stuff;
it never made it into the spec, but I think it was used in other writing early
on.

-s
--
Copyright 2013, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
88888 Dihedral
Guest
Posts: n/a
 
      03-20-2013
Tim Rentsch於 2013年3月20日星期三UTC+8上午6時29分23秒 寫道:
> Seebs <(E-Mail Removed)> writes:
>
>
>
> > On 2013-03-17, Tim Rentsch <(E-Mail Removed)> wrote:

>
> >> 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.

>
> >

>
> > This is interesting. I've often seen "signature" used to refer

>
> > to the function's type, as in "you need a function matching the

>
> > signature of..."

>
>
>
> Yes; it is, regrettably, a common misusage.
>
>
>
> >> Again, this usage is out of step with how the term is used

>
> >> in languages that have an official definition.

>
> >

>
> > I don't have specs for them, but I am not sure that this is

>
> > persuasive in a discussion of C, and even in C++, I see plenty

>
> > of examples of people using the term in the sense of "type of

>
> > arguments and return".

>
>
>

My personally favorite function proto-types in c is the following:

1.
int fun( T* input, T2* output, ... plus call by value parameters)

for any function that could fail an execution code
is returned just mimic a sub-process under the unix system.

2. T fun(T1 input); or T fun(T1* input), T* fun(T1 input),
T* fun(T1 *input ) for those can't fail in the run time.



 
Reply With Quote
 
Philip Lantz
Guest
Posts: n/a
 
      03-20-2013
Tim Rentsch wrote:
> Seebs writes:
> > Tim Rentsch wrote:
> >> 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.

> >
> > This is interesting. I've often seen "signature" used to refer
> > to the function's type, as in "you need a function matching the
> > signature of..."

>
> Yes; it is, regrettably, a common misusage.
>
> >> Again, this usage is out of step with how the term is used
> >> in languages that have an official definition.

> >

> (b) in languages where it does have an official
> definition, it means something significantly different from how
> people often use it here, (c) it's confusing to use a "common"
> term to mean something different from what it officially means,


Agreed, but it's also confusing for a standard to coopt a common term
and give it a definition that differs from the way it is commonly used.
I don't know that that's what has happened with this term in C++, but I
was surprised to read in this thread what the standard definition is,
since it differs from the way I have heard the term used (or at least,
the way I understood it to be used).
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      03-20-2013
On 03/20/2013 05:50 AM, Philip Lantz wrote:
....
> I don't know that that's what has happened with this term in C++, but I
> was surprised to read in this thread what the standard definition is,
> since it differs from the way I have heard the term used (or at least,
> the way I understood it to be used).


Agreed. The distinction, as I remembered it, was that a function's type
was "function returning T", whereas a function's signature was "function
taking this specific list of argument types, returning T", with "..."
being a special case in the argument list. That the function's signature
also includes the name of the function and the namespace in which it is
defined came as a surprise to me, and I'm now wondering where I got the
other idea from, and what aspects of C++ I may have misunderstood as a
result of interpreting that term incorrectly.
--
James Kuyper
 
Reply With Quote
 
Shao Miller
Guest
Posts: n/a
 
      03-20-2013
On 3/20/2013 05:50, Philip Lantz wrote:
> Tim Rentsch wrote:
>> Seebs writes:
>>> Tim Rentsch wrote:
>>>> 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.
>>>
>>> This is interesting. I've often seen "signature" used to refer
>>> to the function's type, as in "you need a function matching the
>>> signature of..."

>>
>> Yes; it is, regrettably, a common misusage.
>>
>>>> Again, this usage is out of step with how the term is used
>>>> in languages that have an official definition.
>>>

>> (b) in languages where it does have an official
>> definition, it means something significantly different from how
>> people often use it here, (c) it's confusing to use a "common"
>> term to mean something different from what it officially means,

>
> Agreed, but it's also confusing for a standard to coopt a common term
> and give it a definition that differs from the way it is commonly used.
> I don't know that that's what has happened with this term in C++, but I
> was surprised to read in this thread what the standard definition is,
> since it differs from the way I have heard the term used (or at least,
> the way I understood it to be used).
>


Suppose you wish to find a function in a library at run-time. One
strategy is to have a "signature" that makes sense to both the
programming language as well as the function-finding, run-time facility.

--
- Shao Miller
--
"Thank you for the kind words; those are the kind of words I like to hear.

Cheerily," -- Richard Harter
 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      03-20-2013
Philip Lantz <(E-Mail Removed)> wrote:
> Tim Rentsch wrote:


(snip)
>> (b) in languages where it does have an official
>> definition, it means something significantly different from how
>> people often use it here, (c) it's confusing to use a "common"
>> term to mean something different from what it officially means,


> Agreed, but it's also confusing for a standard to coopt a common term
> and give it a definition that differs from the way it is commonly used.
> I don't know that that's what has happened with this term in C++, but I
> was surprised to read in this thread what the standard definition is,
> since it differs from the way I have heard the term used (or at least,
> the way I understood it to be used).


Seems to me that Fortran has many terms with different meaning than
the usual CS definition, but in most cases Fortran got there first.

C has many meanings for 'static', only one of corresponding
to the usual definition. (I haven't counted recently.)

-- glen
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      03-20-2013
On 03/20/2013 07:27 AM, James Kuyper wrote:
> On 03/20/2013 05:50 AM, Philip Lantz wrote:
> ...
>> I don't know that that's what has happened with this term in C++, but I
>> was surprised to read in this thread what the standard definition is,
>> since it differs from the way I have heard the term used (or at least,
>> the way I understood it to be used).

>
> Agreed. The distinction, as I remembered it, was that a function's type
> was "function returning T", whereas a function's signature was "function
> taking this specific list of argument types, returning T", with "..."
> being a special case in the argument list.


Correction: the signature does NOT include the function's return type,
and I've even posted messages (many years ago) that reflected a correct
understanding of that point. That was back when I had just finished
studying the 1998 C++ standard, and those concepts were fresher in my mind.

That makes it even more ridiculous to misuse "function signature" as a
synonym for "function type".
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      03-21-2013
glen herrmannsfeldt <(E-Mail Removed)> writes:

> Tim Rentsch <(E-Mail Removed)> wrote:
>
> (snip)
>
>> AFAIK the term 'signature' was first used in the programming
>> language Russell, where it meant something different still, and
>> certainly did not mean 'type', because Russell also used the term
>> 'type' and that was clearly distinct from signatures (among other
>> things, types existed at runtime, whereas signatures existed
>> purely at compile time). (IIRC signatures in Russell were rather
>> elaborate compound entities, and included names of operations.)
>>
>> As far as what may have happened, to me it seems more likely
>> that people picked up the term without really understanding what
>> it meant in the original context, and started using it without
>> knowing what it was supposed to mean, because it sounds more
>> cool and more sophisticated than a short word like type. And
>> unfortunately that misunderstanding has gotten propogated by the
>> term being repeated by further people who mimicked what they
>> heard without bothering to go back and try to find out where
>> the term may have come from. Sometimes that's good for natural
>> language; for technical language it usually isn't.

>
> I suppose, but it seems to me that, at least in some languages,
> it is meant to be the unambiguously unique indication of which
> routine to call. We also hope that our written signatures
> are unambiguously unique, so it makes some sense.


I think you misunderstood what I was trying to say (and maybe I
didn't say it clearly enough, no argument there). In cases like
C++, I think the language definers chose a word and a definition
deliberately, to suit their own purposes; they might or might
not have known about earlier usages in other languages, but that
doesn't matter because they are using the word for a different
purpose. What I was talking about is other people, who are not
language definers, but using what they think is an existing
definition, except their usage is different from the original
definition.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struct pointer vs. struct array pointer aleksa C Programming 16 02-20-2013 08:20 PM
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
(: Pointer to struct withing pointer to struct :) Zero C Programming 16 11-19-2005 01:27 AM
passing pointer->struct->pointer->struct to function. .. ?? beetle C Programming 2 01-25-2005 06:08 PM
Access from function in struct (pointer to function) to other items in the struct (advanced) Ole C Programming 4 10-26-2004 09:43 PM



Advertisments