public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mateusz at loskot dot net" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug libc/10990] New: Inconsistent definition of int64_t in sys/types and stdint.h
Date: Fri, 20 Nov 2009 00:58:00 -0000	[thread overview]
Message-ID: <20091120005823.10990.mateusz@loskot.net> (raw)

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's either incomplete, or some update never made it'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 <inttypes.h>. */
# 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 <sys/types.h> 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 <sys/types.h>
#include <boost/cstdint.hpp>
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

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

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


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

////// $ cat good.cpp //////////////////////////////
#include <stdint.h>
#include <boost/cstdint.hpp>
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

"good.cpp", line 5: warning: variable "a" 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)

-- 
           Summary: Inconsistent definition of int64_t in sys/types and
                    stdint.h
           Product: glibc
           Version: 2.10
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: mateusz at loskot dot net
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=10990

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


             reply	other threads:[~2009-11-20  0:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-20  0:58 mateusz at loskot dot net [this message]
2009-11-20  1:10 ` [Bug libc/10990] " mateusz at loskot dot net
2009-11-20 23:57 ` drepper at redhat dot com
2009-11-22 17:36 ` john at johnmaddock dot co dot uk
2009-11-22 17:42 ` drepper at redhat dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091120005823.10990.mateusz@loskot.net \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).