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 8270739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:40:37+00:00 2026-06-08T06:40:37+00:00

Consider following example code: #include <iostream> #include <inttypes.h> using namespace std; int f(uint32_t i)

  • 0

Consider following example code:

#include <iostream>
#include <inttypes.h>

using namespace std;

int f(uint32_t i)
{
  return 1;
}
int f(uint64_t i)
{
  return 2;
}

int main ()
{
  cout << sizeof(long unsigned) << '\n';
  cout << sizeof(size_t) << '\n';
  cout << sizeof(uint32_t) << '\n';
  cout << sizeof(uint64_t) << '\n';
  //long unsigned x = 3;
  size_t x = 3;
  cout << f(x) << '\n';
  return 0;
}

This fails on Mac OSX with:

$ g++ --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
$ make test
g++     test.cc   -o test
test.cc: In function 'int main()':
test.cc:23: error: call of overloaded 'f(size_t&)' is ambiguous
test.cc:6: note: candidates are: int f(uint32_t)
test.cc:10: note:                 int f(uint64_t)
make: *** [test] Error 1

Why? Because ‘size_t’ should be unsigned and either 32 bit or 64 bit wide. Where is the ambiguity then?

Trying the same with ‘unsigned long x’ instead of ‘size_t x’ results in an
analogous ambiguity error message.

On Linux/Solaris systems, testing with different GCC versions, different architectures etc. there is no ambiguity reported (and the right overload is used on each architecture).

Is this a Mac OS X bug or a feature?

  • 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-08T06:40:39+00:00Added an answer on June 8, 2026 at 6:40 am

    Under Mac OS, those types are defined as:

    typedef unsigned int         uint32_t;
    typedef unsigned long long   uint64_t;
    

    Where as size_t is defined as __SIZE_TYPE__:

    #if defined(__GNUC__) && defined(__SIZE_TYPE__)
    typedef __SIZE_TYPE__       __darwin_size_t;    /* sizeof() */
    #else
    typedef unsigned long       __darwin_size_t;    /* sizeof() */
    #endif
    

    So if you change your code to:

    #include <iostream>
    #include <inttypes.h>
    
    using namespace std;
    
    int f(uint32_t i)
    {
      return 1;
    }
    int f(uint64_t i)
    {
      return 2;
    }
    
    int f (unsigned long i)
    {
      return 3;
    }
    
    int main ()
    {
      cout << sizeof(unsigned long) << '\n';
      cout << sizeof(size_t) << '\n';
      cout << sizeof(uint32_t) << '\n';
      cout << sizeof(uint64_t) << '\n';
      //long unsigned x = 3;
      size_t x = 3;
      cout << f(x) << '\n';
      return 0;
    }
    

    And run it, you will get:

    $ g++ -o test test.cpp
    $ ./test
    8
    8
    4
    8
    3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please consider following code #include <iostream> using namespace std; class Digit { private: int
Consider the following sample code: #include <iostream> using namespace std; class base { public:
Consider the following x86 code example: #include <stdlib.h> static int i; static inline __attribute__((always_inline))
Consider the following C++ code example: int array_1[] = {5,6,7}; int array_2[] = {6,7,8,9};
Consider the following code: #include <iostream> struct X{ X(){ throw 0; } }; void
Consider the following code, compiled with g++ problem.cpp -o problem : #include <vector> using
Please consider the following example code (from the lm doc): ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?
Consider the following example program: next :: Int -> Int next i | 0
Consider the following example: int size = 10, *kk = new int[size]; for (int

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.