Opened 10 years ago

Closed 10 years ago

#7389 closed Bugs (fixed)

__STDC_LIMIT_MACROS can be redefined by boost when using mingw32

Reported by: chfast@… Owned by: John Maddock
Milestone: To Be Determined Component: config
Version: Boost 1.51.0 Severity: Problem
Keywords: Cc:

Description (last modified by viboes)

On Windows, compiling with mingw32, STDC_LIMIT_MACROS macro is redefined if it was already defined.

This macro is defined in boost/config/platform/win32.hpp by

#if defined(__MINGW32__) && ((__MINGW32_MAJOR_VERSION > 2) || ((__MINGW32_MAJOR_VERSION == 2) && (__MINGW32_MINOR_VERSION >= 0)))
#  define BOOST_HAS_STDINT_H
#  define __STDC_LIMIT_MACROS
#  define BOOST_HAS_DIRENT_H
#  define BOOST_HAS_UNISTD_H
#endif

Maybe it can be changed to:

#if defined(__MINGW32__) && ((__MINGW32_MAJOR_VERSION > 2) || ((__MINGW32_MAJOR_VERSION == 2) && (__MINGW32_MINOR_VERSION >= 0)))
#  define BOOST_HAS_STDINT_H
#  if !defined(__STDC_LIMIT_MACROS)
#    define __STDC_LIMIT_MACROS
#  endif
#  define BOOST_HAS_DIRENT_H
#  define BOOST_HAS_UNISTD_H
#endif

Attachments (1)

win32.hpp.patch (455 bytes ) - added by Paweł Bylica <chfast@…> 10 years ago.
A patch

Download all attachments as: .zip

Change History (10)

comment:1 by viboes, 10 years ago

Component: Noneconfig
Owner: set to John Maddock

by Paweł Bylica <chfast@…>, 10 years ago

Attachment: win32.hpp.patch added

A patch

comment:2 by viboes, 10 years ago

Description: modified (diff)

comment:3 by John Maddock, 10 years ago

(In [82998]) Fix for STDC_LIMIT_MACROS already defined. Refs #7389.

comment:4 by viboes, 10 years ago

Why do we need to define

__STDC_LIMIT_MACROS

?

What happens if the user include the files using this macro before the boost config files?

Last edited 10 years ago by viboes (previous) (diff)

comment:5 by anonymous, 10 years ago

What happens if the user include the files using this macro before the boost config files?

We have to fall back to code that doesn't depend on UINT8_MAX etc being defined. Ideally if stdint.h is included twice - once without __STDC_LIMIT_MACROS and then again with it, it will do the right thing and fill in the definitions it missed out the first time. Not all implementations do that though :-(

in reply to:  5 comment:6 by viboes, 10 years ago

Replying to anonymous:

What happens if the user include the files using this macro before the boost config files?

We have to fall back to code that doesn't depend on UINT8_MAX etc being defined. Ideally if stdint.h is included twice - once without __STDC_LIMIT_MACROS and then again with it, it will do the right thing and fill in the definitions it missed out the first time. Not all implementations do that though :-(

Isn't stdint.h protected for multiple inclusions?

comment:7 by anonymous, 10 years ago

Isn't stdint.h protected for multiple inclusions?

Maybe!

In C99 it defines different things depending on whether __STDC_LIMIT_MACROS is defined or not, so rather like assert.h with NDEBUG it should really "correct itself" each time it's included depending upon the value of the macro. Thankfully C++11 does the sane thing and just requires that the limit macros are always defined.

Either way, we should really try to get the system defined limits macros if we can, just because we can't be certain of getting them every time, isn't a reason not to try.

in reply to:  7 comment:8 by viboes, 10 years ago

Replying to anonymous:

Isn't stdint.h protected for multiple inclusions?

Maybe!

In C99 it defines different things depending on whether __STDC_LIMIT_MACROS is defined or not, so rather like assert.h with NDEBUG it should really "correct itself" each time it's included depending upon the value of the macro. Thankfully C++11 does the sane thing and just requires that the limit macros are always defined.

Thanks for the explanation, I didn't know about this requirement.

Either way, we should really try to get the system defined limits macros if we can, just because we can't be certain of getting them every time, isn't a reason not to try.

Agreed.

comment:9 by John Maddock, 10 years ago

Resolution: fixed
Status: newclosed

(In [83139]) Merge changes from Trunk. Fixes #6013. Fixes #7151. Fixes #7359. Fixes #7389. Fixes #7452. Fixes #7528. Fixes #7703. Fixes #7841. Fixes #7898. Fixes #7938. Fixes #8048.

Note: See TracTickets for help on using tickets.