[bind10-dev] int64_t and function overloading

fujiwara at jprs.co.jp fujiwara at jprs.co.jp
Fri Jun 28 10:55:17 UTC 2013


I faced C++ overloading problem.

Element->create() defined in src/lib/cc/data.h is overloaded and
accepts "long int", "int", "double", "bool", "string&" and "char*".

I tried to change "long int" to "int64_t" and prepare "int32_t" function.

C++ compiler does not match "long int" and "int32_t" on 32bit systems and
                            "long long int" and "int64_t" on 64bit systems.

Function declaration side, "int64_t" and "long int" are treated as
same on 64bit systems.

Using three types "long long int", "long int" and "int" works well.

My result is that we cannot use int64_t or int32_t on overloading functions.

Is it true?

Test code is here:
--------------------------------------------------------------------------
#include <stdint.h>
#include <string>
#include <iostream>

using namespace std;

static void f(const double d)   { cout << "double: "  << d << endl; }
static void f(const int64_t n)  { cout << "int64_t: " << n << endl; }
static void f(const int32_t n)  { cout << "int32_t: " << n << endl; }
static void f(const string& s)  { cout << "string&: " << s << endl; }
static void f(const char* s)    { cout << "char*: "   << s << endl; }

main()
{
        long int l = 100;
        long long int ll = 100;
        int64_t i64 = 100;
        int32_t i32 = 100;
        f(l);
        f(ll);
        f(i64);
        f(i32);
}
-------------------------------------------------------------------------

Workable  test code:
--------------------------------------------------------------------------
#include <stdint.h>
#include <string>
#include <iostream>

using namespace std;

static void f(const double d)  { cout << "double: " << d << endl; }
static void f(const long long int n)  { cout << "long long int: " << n << endl; }
static void f(const long int n) { cout << "long int: " << n << endl; }
static void f(const int n)     { cout << "int: " << n << endl; }
static void f(const string& s) { cout << "string&: " << s << endl;  }
static void f(const char* s)   { cout << "char*: " << s << endl; }

main()
{
        long int l = 100;
        long long int ll = 100;
        int64_t i64 = 100;
        int32_t i32 = 100;
        f(l);
        f(ll);
        f(i64);
        f(i32);
}
-------------------------------------------------------------------------

Regards,

--
Kazunori Fujiwara, JPRS <fujiwara at jprs.co.jp>


More information about the bind10-dev mailing list