<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://sourceware.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="4.4+"
          urlbase="http://sourceware.org/bugzilla/"
          
          maintainer="overseers@sourceware.org"
>

    <bug>
          <bug_id>10990</bug_id>
          
          <creation_ts>2009-11-20 00:58:00 +0000</creation_ts>
          <short_desc>Inconsistent definition of int64_t in sys/types and stdint.h</short_desc>
          <delta_ts>2009-11-22 17:42:33 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>glibc</product>
          <component>libc</component>
          <version>2.9</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Mateusz Loskot">mateusz</reporter>
          <assigned_to name="Ulrich Drepper">drepper.fsp</assigned_to>
          <cc>glibc-bugs</cc>
    
    <cc>john</cc>
          <cf_gcchost></cf_gcchost>
          <cf_gcctarget></cf_gcctarget>
          <cf_gccbuild></cf_gccbuild>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>39948</commentid>
    <comment_count>0</comment_count>
    <who name="Mateusz Loskot">mateusz</who>
    <bug_when>2009-11-20 00:58:23 +0000</bug_when>
    <thetext>I found it odd and problematic that two glibc headers seem to compete with each
other regarding definition of int64_t (and probably uint64_t as well). It looks
like it&apos;s either incomplete, or some update never made it&apos;s way into the source
tree, or, there is some rarer side issue which comes up and that they headers
are this way on purpose.

Here are details:

1) Header file /usr/include/sys/types.h defines int64_t as follows:

/* These types are defined by the ISO C99 header &lt;inttypes.h&gt;. */
# ifndef __int8_t_defined
#  define __int8_t_defined
typedef	char int8_t;
typedef	short int int16_t;
typedef	int int32_t;
#  if __WORDSIZE == 64
typedef long int int64_t;
#  elif __GLIBC_HAVE_LONG_LONG
__extension__ typedef long long int int64_t;
#  endif
# endif

2) Header /usr/include/stdint.h also defines int64_t but slightly differently:

/* There is some amount of overlap with &lt;sys/types.h&gt; as known by inet code */
#ifndef __int8_t_defined
# define __int8_t_defined
typedef signed char		int8_t;
typedef short int		int16_t;
typedef int			int32_t;
# if __WORDSIZE == 64
typedef long int		int64_t;
# else
__extension__
typedef long long int		int64_t;
# endif
#endi
# endif

As the comment states, this file does repeat some type definitions.
However, definition of int64_t is different, it is not guarded with
__GLIBC_HAVE_LONG_LONG preprocessor definition.

This difference causes problems, for example, when using some of libraries from
Boost C++ collection and compiling with Comeau C/C++ Compiler front-end.
Here is original report I submitted to Boost
(https://svn.boost.org/trac/boost/ticket/3548).


Here are small tests that present how use of sys/types.h vs stdint.h influence
compilation result if int64_t type is used:

1) Include sys/types.h and compilation fails:

////// $ cat bad.cpp ///////////////////////////////
#include &lt;sys/types.h&gt;
#include &lt;boost/cstdint.hpp&gt;
int main()
{
    boost::int64_t a(0);
    return 0;
}

$ como -I/home/mloskot/dev/boost/_svn/trunk bad.cpp 
Comeau C/C++ 4.3.10.1 (May  7 2008 12:23:21) for LINUX_INTEL_ELF_Beta
Copyright 1988-2008 Comeau Computing.  All rights reserved.
MODE:non-strict warnings C++ noC++0x_extensions

&quot;/home/mloskot/dev/boost/_svn/trunk/boost/cstdint.hpp&quot;, line 111: error: the
          global scope has no &quot;int64_t&quot;
    using ::int64_t;            
            ^

&quot;bad.cpp&quot;, line 5: error: namespace &quot;boost&quot; has no member &quot;int64_t&quot;
      boost::int64_t a(0);
             ^


2) 1) Include stdint.h and compilation fails:

////// $ cat good.cpp //////////////////////////////
#include &lt;stdint.h&gt;
#include &lt;boost/cstdint.hpp&gt;
int main()
{
    boost::int64_t a(0);
    return 0;
}

$ como -I/home/mloskot/dev/boost/_svn/trunk good.cpp 
Comeau C/C++ 4.3.10.1 (May  7 2008 12:23:21) for LINUX_INTEL_ELF_Beta
Copyright 1988-2008 Comeau Computing.  All rights reserved.
MODE:non-strict warnings C++ noC++0x_extensions

&quot;good.cpp&quot;, line 5: warning: variable &quot;a&quot; was declared but never referenced
      boost::int64_t a(0);
                     ^


It is important to notice that int64_t is defined only if __GLIBC_HAVE_LONG_LONG.
I checked the two headers in current glibc git repository and it still includes
those definitions of int64_t, thus I decided to submit bug report directly to glibc
instead of Ubuntu team (I use glibc from Ubuntu packages):
(http://sourceware.org/git/?p=glibc.git;a=blob;f=posix/sys/types.h#l160)
(http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/generic/stdint.h#l34)


Environment:
* OS: Linux / Ubuntu 9.10
* GCC: gcc(Ubuntu 4.4.1-4ubuntu8) 4.4.1
* glibc: 2.10.1-0ubuntu15 (http://packages.ubuntu.com/karmic/libc6-dev)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>39949</commentid>
    <comment_count>1</comment_count>
    <who name="Mateusz Loskot">mateusz</who>
    <bug_when>2009-11-20 01:10:05 +0000</bug_when>
    <thetext>(In reply to comment #0)
&gt; Environment:
&gt; * OS: Linux / Ubuntu 9.10
&gt; * GCC: gcc(Ubuntu 4.4.1-4ubuntu8) 4.4.1
&gt; * glibc: 2.10.1-0ubuntu15 (http://packages.ubuntu.com/karmic/libc6-dev)

*** CORRECTION TO ENVIRONMENT *** 

I&apos;m terribly sorry for my mistake. I&apos;ve given details of my other
machine/system. Here are correct details of system on which the problem leaks
and on which I prepared the two test programs:

* Linux Ubuntu 9.04 32-bit
* GCC 4.3.3
* glibc 2.9-4ubuntu (http://packages.ubuntu.com/jaunty/libc6-dev)
* Comeau C/C++ Compiler front-end 4.3.10.1

I&apos;ve also changed the glibc version to which this report applies from 2.10 to 2.9. 

I&apos;m sorry for confusion.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>39972</commentid>
    <comment_count>2</comment_count>
    <who name="Ulrich Drepper">drepper.fsp</who>
    <bug_when>2009-11-20 23:57:34 +0000</bug_when>
    <thetext>stdint.h is a C99 header and C99 demands the implementation of long long.  The
headers are correct.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>39988</commentid>
    <comment_count>3</comment_count>
    <who name="John Maddock">john</who>
    <bug_when>2009-11-22 17:35:55 +0000</bug_when>
    <thetext>The point here is that stdint.h behaves differently depending upon what has been
#included previously, for example:

#include &lt;sys/types.h&gt; // possibly included from some deep dependency
#include &lt;stdint.h&gt;

May *NOT* result in int64_t being defined if __GLIBC_HAVE_LONG_LONG
 is not set, where as had stdint.h been the first include then it *would* have
been defined.

In other words stdint.h may not follow the C99 std depending upon what has
happened to be included previously.

Still think it&apos;s not a bug?

IMO stdint.h should always define int64_t no matter what other headers may have
been included first.

John Maddock.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>39989</commentid>
    <comment_count>4</comment_count>
    <who name="Ulrich Drepper">drepper.fsp</who>
    <bug_when>2009-11-22 17:42:33 +0000</bug_when>
    <thetext>You cannot have __GLIBC_HAVE_LONG_LONG *not* be defined if you include stdint.h.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>