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

  • SEARCH
  • Home
  • 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 8555117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:02:57+00:00 2026-06-11T15:02:57+00:00

Consider the following code: #include <iostream> #include <cinttypes> template<class T> void f(); template<> inline

  • 0

Consider the following code:

#include <iostream>
#include <cinttypes>  

template<class T>
void f();

template<>
inline void f<long long>() {
  std::cout<<"f<long long>()"<<std::endl;
}

int main(int , char** ) {
  std::cout<<"sizeof(long)="<<sizeof(long)<<std::endl;
  std::cout<<"sizeof(long long)="<<sizeof(long long)<<std::endl;
  f<int64_t>();
  return 0;
}

32-bit G++ 4.6.3 compiles this successfully and produces the output:

sizeof(long)=4
sizeof(long long)=8
f<long long>()

Compiling under 64-bit G++ 4.6.3 however produces the linker error:

undefined reference to `void f<long>()'
ld returned 1 exit status

even though compiling and running with the f<int64_t>() line commented out produces:

sizeof(long)=8
sizeof(long long)=8

Is there a good reason why 64-bit G++ treats f<long> and f<long long> as different functions, even though long and long long are the same size, or is this a bug that I should report?

  • 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-06-11T15:02:59+00:00Added an answer on June 11, 2026 at 3:02 pm

    The underlying type of int64_t can be anything that meets the requirements. It’s okay to make it long on one platform and long long on another.

    Since you provide a specialization for long long and the generic version has no body, if int64_t is not a long long you get an undefined reference.

    And yes, there is a good reason why f<long> and f<long long> are different functions: it’s because the standard says that long and long long are distinct types. The fact that they happen to be the same width on some platform doesn’t matter, especially because they may be of different widths on another.

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

Sidebar

Related Questions

Consider the following code: #include <iostream> using namespace std; class Test { static int
Consider the following code: #include<iostream> using namespace std; class sample { int a; int
please consider following code #include <iostream> using namespace std; class Digit { private: int
Consider the following code: #include <iostream> #include <cstdio> #include <cstring> using namespace std; template<class
Consider the following code: #include <iostream> using namespace std; int main() { int x,
Please consider the following code: #include <iostream> #include <typeinfo> template< typename Type > void
Consider the following code : #include <vector> #include <iostream> class a { public: int
Consider the following sample code: #include <iostream> using namespace std; class base { public:
Consider the following code : #include <iostream> #include <type_traits> template<typename T> class MyClass {
Consider the following code: #include <iostream> using namespace std; class B{ public: B(){} };

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.