incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: [PATCH] STDCXX-423
Date Tue, 12 Feb 2008 23:16:55 GMT
Sorry Scott, I still don't understand what you're trying to do here.

The problem noted in STDCXX-423 is pretty much theoretical. AFAIK,
stdcxx doesn't build or run on any platform with padding bits. In
fact, there may not be any such platforms. Which doesn't mean that
there will never be any (as pointed out in the comp.lang.c thread
I just updated the issue with), just that coming up with a test
case will be tough, as will be testing a patch for the problem.

Martin

Scott Zhong wrote:
> --- LIMITS.cpp  (revision 624452)
> +++ LIMITS.cpp  (working copy)
> @@ -223,13 +223,27 @@
>      return bits;
>  }
>  
> +template <class T>
> +unsigned compute_byte_size()
> +{
> +    T max = T (one);
> +    unsigned byte = 1;
> +    for (int i = 1; T (max * two) > max; max *= two, i++) { 
> +        if (i > 8 ) {byte++; i = 1; } 
> +    }
> +    return byte; 
> +}
>  
> +
>  // used to compute the size of a pointer to a member function
>  struct EmptyStruct { };
>  
>  
>  // to silence printf() format comaptibility warnings
>  #define SIZEOF(T)   unsigned (sizeof (T))
> + 
> +// to not include possible bit padding
> +#define CALC_SIZEOF(T)  compute_byte_size<T>()
>  
>  
>  int main ()
> @@ -243,17 +257,17 @@
>  
>  #ifndef _RWSTD_NO_BOOL
>      printf ("#define _RWSTD_BOOL_SIZE   %2u /* sizeof (bool) */\n",
> -            SIZEOF (bool));
> +            CALC_SIZEOF (bool));
>  #endif   // _RWSTD_NO_BOOL
>  
>      printf ("#define _RWSTD_CHAR_SIZE   %2u /* sizeof (char) */\n",
> -            SIZEOF (char));
> +            CALC_SIZEOF (char));
>      printf ("#define _RWSTD_SHRT_SIZE   %2u /* sizeof (short) */\n",
> -            SIZEOF (short));
> +            CALC_SIZEOF (short));
>      printf ("#define _RWSTD_INT_SIZE    %2u /* sizeof (int) */\n",
> -            SIZEOF (int));
> +            CALC_SIZEOF (int));
>      printf ("#define _RWSTD_LONG_SIZE   %2u /* sizeof (long) */\n",
> -            SIZEOF (long));
> +            CALC_SIZEOF (long));
>  
>      printf ("#define _RWSTD_FLT_SIZE    %2u /* sizeof (float) */\n",
>              SIZEOF (float));
> @@ -319,7 +333,7 @@
>  
>  #    define LLong long long
>  
> -    printf ("#define _RWSTD_LLONG_SIZE  %2u\n", SIZEOF (LLong));
> +    printf ("#define _RWSTD_LLONG_SIZE  %2u\n", CALC_SIZEOF (LLong));
>  
>      const char llong_name[] = "long long";
>  
> @@ -332,7 +346,7 @@
>  
>  #    define LLong __int64
>  
> -    printf ("#define _RWSTD_LLONG_SIZE  %2u\n", SIZEOF (LLong));
> +    printf ("#define _RWSTD_LLONG_SIZE  %2u\n", CALC_SIZEOF (LLong));
>  
>      const char llong_name[] = "__int64";
>  
> @@ -352,7 +366,7 @@
>  #ifndef _RWSTD_NO_WCHAR_T
>  
>      printf ("#define _RWSTD_WCHAR_SIZE  %2u /* sizeof (wchar_t) */\n",
> -            SIZEOF (wchar_t));
> +            CALC_SIZEOF (wchar_t));
>  
>      const char *suffix = "U";
>      if ((wchar_t)~0 < (wchar_t)0)
> 


Mime
View raw message