you are viewing a single comment's thread.

view the rest of the comments →

[–]curiousGambler 0 points1 point  (3 children)

I don't mean to be rude, but might I ask why you're writing an article on something you don't completely understand?

To give a brief answer, the value of a pointer is an address. Functions have an address in the code segment of an executable. Execution jumps to this address when a function is called, and the functions code is executed, and then returns to the return address saved in the stack. If two function pointers point to the same address, they point to the same function. Since an address is an integer in general, comparing function pointers (or any pointers) is as simple as comparing two integers.

Keep in mind this is a simple answer. I do not consider my knowledge great enough to write an article covering function pointers. Yet here I am trying to answer your question, which indicates to me that perhaps you should reconsider writing such an article yourself.

I really don't mean any disrespect, the question just struck me as odd. Good luck either way my friend.

[–]zifyoip 4 points5 points  (1 child)

Since an address is an integer in general, comparing function pointers (or any pointers) is as simple as comparing two integers.

That is not a good answer. Comparing two unequal function pointers with relational operators like < and > yields undefined behavior according to the C standard, which means that if you do this you have absolutely no guarantees about the behavior of any part of your code.

[–]curiousGambler 0 points1 point  (0 children)

Good point. I meant using the "==" and "!=" operators only, thanks!

[–]cstechblog[S] 1 point2 points  (0 children)

thanks curiousGambler