Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6984553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:33:51+00:00 2026-05-27T18:33:51+00:00

Is it safe to assume that two function pointers, that point to different instances

  • 0

Is it safe to assume that two function pointers, that point to different instances of one templated function, will compare unequal?
Even if the templated function does not use the template parameter(s) at all and thus does the exact same thing in every case?

For example the following works fine on my compiler but I’m not sure if it does on any other:

class TypeChecker
{
public:
    template< typename T > static void foo( void )
    {}
    template< typename T > static void setType( void )
    { s_fooPtr = &foo< T >; }
    template< typename T > static bool checkType( void )
    { return ( s_fooPtr == &foo< T > ); }
private:
    static void ( * s_fooPtr )( void );
};

void ( * TypeChecker::s_fooPtr )( void ) = 0;

int main( void )
{
    TypeChecker::setType< char >();
    TypeChecker::checkType< char >();           // true
    TypeChecker::checkType< unsigned char >();  // false
    TypeChecker::checkType< signed char >();    // false
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:33:52+00:00Added an answer on May 27, 2026 at 6:33 pm

    When will two pointer compare equal?

    According to 5.10/1:

    The == (equal to) and the != (not equal to) operators have the same
    semantic restrictions, conversions, and result type as the relational
    operators except for their lower precedence and truth-value result. [
    Note: a<b
    == c<d
    is true whenever a<b and c<d have the same truth-value. —end note ] Pointers of the same type (after pointer conversions) can be
    compared for equality. Two pointers of the same type compare equal if
    and only if they are both null, both point to the same function, or
    both represent the same address (3.9.2).

    Are foo<int>() and foo<char>() the same function?

    According to 14.4/1:

    Two template-ids refer to the same class or function if

    • their template-names, operator-function-ids, or literal-operator-ids refer to the same template and
    • their corresponding type template-arguments are the same type and
    • their corresponding non-type template arguments of integral or enumeration type have identical values
      and
    • their corresponding non-type template-arguments of pointer type refer to the same external object or
      function or are both the null pointer value and
    • their corresponding non-type template-arguments of pointer-to-member type refer to the same class
      member or are both the null member pointer value and
    • their corresponding non-type template-arguments of reference type refer to the same external object
      or function and
    • their corresponding template template-arguments refer to the same template.

    So apparently foo<int>() and foo<char>() are not the same function.

    So &foo<int>() and &foo<char>() should not compare equal, whatever optimization is made.


    EDIT:

    As mentioned by @SergeDundich in the comment, 14.4/1 used if instead if and only if, which gives no guarantee whether foo<int>() and foo<char>() are the same function or not. In other parts of the specification, if and only if is used a lot.

    I didn’t find any clarification to this in the specification. However, in the examples, I can find this:

    template<class T, void(*err_fct)()> class list { /* ... */ };
    list<int,&error_handler1> x1;
    list<int,&error_handler2> x2;
    list<int,&error_handler2> x3;
    list<char,&error_handler2> x4;
    

    declares x2 and x3 to be of the same type. Their type differs from the
    types of x1 and x4.


    EDIT2:

    if is used instead of if and only if as this situation exists: (Example from 14.5.7/2)

    template<class T> struct Alloc { /* ... */ };
    template<class T> using Vec = vector<T, Alloc<T>>;
    Vec<int> v; // same as vector<int, Alloc<int>> v;
    

    Vec<int> and vector<int, Alloc<int>> have a lot of differences, but still the same type.

    However, as to the case of foo<int>() and foo<char>(), their signatures are different. The different signatures should render them different functions.

    Thanks to @JohannesSchaub-litb .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it safe to assume that two itterations over the same collection will return
Is it safe to assume that java.util.concurrent.CompletionService.take().isDone() will always return true? If so, why
std::map<int,int> mapy; ++mapy[5]; Is it safe to assume that mapy[5] will always be 1?
Is it safe to assume that all implementations of org.springframework.context.MessageSource interface are thread-safe after
Is it safe to assume that event subscribers are called in order of subscription?
Is it safe to assume that NULL always translates to false in C? void
Is it safe to assume that $_SERVER['REMOTE_ADDR'] always returns a IPv4 address ? Thanks!
It is safe to assume that working with or passing around an immutable object
Is it safe to assume that WPF TwoWay data binding Wont work on controls
Is it safe to assume that when a user requests an .aspx page via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.