Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Can function pointers be compared for equality |
| Date | 2012-01-23 09:11 -0800 |
| Organization | None to speak of |
| Message-ID | <ln8vkywdi3.fsf@nuthaus.mib.org> (permalink) |
| References | <16c3fab7-bcd4-40dd-8208-93e7358dec1e@kn4g2000pbc.googlegroups.com> <ad3ff3b8-b520-40f0-8e73-4a66a1426e37@n6g2000vbz.googlegroups.com> |
Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> <subramanian10...@yahoo.com> wrote:
>>
>> Is this equality comparison check of function pointers, legal, correct
>> and allowed ? (Note that it works in my implementation of gcc. But I
>> do not want to go by one particular implementation).
>>
>> Please explain.
>>
> You can compare function ponters for equality. However you can't
> compare for inequality. The > and < operators only refer to pointers
> which are within the same object, and two fucntion pointers cannot be
> within the same object, except for the special case of identity.
Function pointers never point to *any* object. The relational
operators (< <= > >=) are not defined for function pointers because
the standard doesn't define them. Two function pointers are equal,
as determined by the = and ~= operator, if and only if they're both
null pointers or they both point to the same function.
> However on most platforms code addresses can be sorted into ascending
> or descending order, and comparison for inequality will work as you
> would expect. Also, you can convert the pointer to a raw stream of
> bytes, and comparision must work.
x < y, where x and y are function pointers, is a constraint
violation; a conforming compiler must issue a diagnostic, and
may reject the translation unit. Comparing the raw bytes is not
guaranteed to be meaningful.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can function pointers be compared for equality "V.Subramanian, India" <subramanian100in@yahoo.com> - 2012-01-23 05:54 -0800
Re: Can function pointers be compared for equality Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-23 07:00 -0800
Re: Can function pointers be compared for equality blp@cs.stanford.edu (Ben Pfaff) - 2012-01-23 07:46 -0800
Re: Can function pointers be compared for equality Kaz Kylheku <kaz@kylheku.com> - 2012-01-23 20:06 +0000
Re: Can function pointers be compared for equality ec429 <ec429@cam.ac.uk> - 2012-01-23 20:42 +0000
Re: Can function pointers be compared for equality James Kuyper <jameskuyper@verizon.net> - 2012-01-23 16:04 -0500
Re: Can function pointers be compared for equality Ian Collins <ian-news@hotmail.com> - 2012-01-24 10:24 +1300
Re: Can function pointers be compared for equality James Kuyper <jameskuyper@verizon.net> - 2012-01-23 16:48 -0500
Re: Can function pointers be compared for equality Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-24 03:04 -0800
Re: Can function pointers be compared for equality gwowen <gwowen@gmail.com> - 2012-01-24 03:37 -0800
Re: Can function pointers be compared for equality Kleuske <kleuske@nowhere.net> - 2012-01-23 21:39 +0000
Re: Can function pointers be compared for equality gwowen <gwowen@gmail.com> - 2012-01-24 03:31 -0800
Re: Can function pointers be compared for equality ec429 <ec429@cam.ac.uk> - 2012-01-24 13:16 +0000
Re: Can function pointers be compared for equality Kaz Kylheku <kaz@kylheku.com> - 2012-01-23 22:11 +0000
Re: Can function pointers be compared for equality Ian Collins <ian-news@hotmail.com> - 2012-01-24 11:34 +1300
Re: Can function pointers be compared for equality Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-23 16:37 +0000
Re: Can function pointers be compared for equality Keith Thompson <kst-u@mib.org> - 2012-01-23 09:11 -0800
Re: Can function pointers be compared for equality pete <pfiland@mindspring.com> - 2012-01-23 20:06 -0500
Re: Can function pointers be compared for equality Keith Thompson <kst-u@mib.org> - 2012-01-23 17:45 -0800
Re: Can function pointers be compared for equality Kaz Kylheku <kaz@kylheku.com> - 2012-01-24 03:48 +0000
Re: Can function pointers be compared for equality James Kuyper <jameskuyper@verizon.net> - 2012-01-23 22:59 -0500
Re: Can function pointers be compared for equality Kaz Kylheku <kaz@kylheku.com> - 2012-01-24 04:22 +0000
Re: Can function pointers be compared for equality Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-24 03:07 -0800
Re: Can function pointers be compared for equality Kleuske <kleuske@nowhere.net> - 2012-01-24 11:16 +0000
csiph-web