Worrying Prevalence of K++ Compilers

  • Follow


It seems there's quite a few compilers out there that don't follow the C++ 
Standard when it comes to default-initialisation. Here's some quick test 
code if anyone would like to try it out. So far, it seems to identify g++ 
and VC++ as K++ compilers.

#include <cstddef>

template <class T,std::size_t len>
bool IsAnyElementTrue(T const (&arr)[len])
{
     T const *p = arr;
     T const *const pover = arr + len;

     do if (*p++) return true;
     while (pover != p);

     return false;
}

#include <iostream>
#include <ostream>
using std::cout;
using std::endl;

int main()
{
     int arr1[32] = {};
     double arr2[32] = {};
     char *arr3[32] = {};

     int (&arr4)[32] = *new int[1][32]();
     double (&arr5)[32] = *new double[1][32]();
     char *(&arr6)[32] = *new char*[1][32]();

     if (IsAnyElementTrue(arr1)) cout << "Problem with arr1." << endl;
     if (IsAnyElementTrue(arr2)) cout << "Problem with arr2." << endl;
     if (IsAnyElementTrue(arr3)) cout << "Problem with arr3." << endl;
     if (IsAnyElementTrue(arr4)) cout << "Problem with arr4." << endl;
     if (IsAnyElementTrue(arr5)) cout << "Problem with arr5." << endl;
     if (IsAnyElementTrue(arr6)) cout << "Problem with arr6." << endl;

     delete [] &arr4;
     delete [] &arr5;
     delete [] &arr6;
}

-- 

Frederick Gotham
0
Reply fgothamNO (1668) 11/8/2006 7:17:34 PM

Frederick Gotham wrote:
> It seems there's quite a few compilers out there that don't follow
> the C++ Standard when it comes to default-initialisation. Here's some
> quick test code if anyone would like to try it out. So far, it seems
> to identify g++ and VC++ as K++ compilers.

Which VC++?  I just ran your code after compiling it on VC++ 2005 and
it reported no problem.

Which g++?

And perhaps next time compiler-specific stuff will be posted to that
compiler's newsgroup...

>
> [redacted]

V
-- 
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask 


0
Reply v.Abazarov (13255) 11/8/2006 7:22:29 PM


Victor Bazarov:

> Which VC++?  I just ran your code after compiling it on VC++ 2005 and
> it reported no problem.


Over on comp.lang.c++.moderated, werasm reported that it failed on VCC 7.1.


> Which g++?


It failed on Version 3.4.2 for me.

 
> And perhaps next time compiler-specific stuff will be posted to that
> compiler's newsgroup...


I thought it would be appropriate here seeing as though it affects more than 
one popular compiler.

-- 

Frederick Gotham
0
Reply fgothamNO (1668) 11/8/2006 7:41:50 PM

Frederick Gotham wrote:
> Victor Bazarov:
>
>> Which VC++?  I just ran your code after compiling it on VC++ 2005 and
>> it reported no problem.
>
>
> Over on comp.lang.c++.moderated, werasm reported that it failed on
> VCC 7.1.
>
>
>> Which g++?
>
>
> It failed on Version 3.4.2 for me.
>
>
>> And perhaps next time compiler-specific stuff will be posted to that
>> compiler's newsgroup...
>
>
> I thought it would be appropriate here seeing as though it affects
> more than one popular compiler.

.... both of which have been already updated.  You could also try Turbo
C++ v2 or Watcom C++ v10 or Zortech C++ v3...  They will probably fail
even more miserably. 


0
Reply v.Abazarov (13255) 11/8/2006 8:05:25 PM

Frederick Gotham wrote:
> 
>>Which g++?
> 
> It failed on Version 3.4.2 for me.

   Works on 3.4.6 for me.

- J.
0
Reply jacek6764 (158) 11/8/2006 8:47:08 PM

"Frederick Gotham" <fgothamNO@SPAM.com> wrote in message 
news:2qq4h.15790$j7.333500@news.indigo.ie...
> Victor Bazarov:
>
>> Which VC++?  I just ran your code after compiling it on VC++ 2005 and
>> it reported no problem.
>
>
> Over on comp.lang.c++.moderated, werasm reported that it failed on VCC 
> 7.1.

VCC 7.1 is Visual C++ .net 2003.  It is 3 years old.  Someone reported it 
works on 2005 (8.0 I believe).

>> Which g++?
>
>
> It failed on Version 3.4.2 for me.
>
>
>> And perhaps next time compiler-specific stuff will be posted to that
>> compiler's newsgroup...
>
>
> I thought it would be appropriate here seeing as though it affects more 
> than
> one popular compiler.
>
> -- 
>
> Frederick Gotham 


0
Reply tazmaster (2359) 11/9/2006 11:48:11 AM

Frederick Gotham wrote:
> It seems there's quite a few compilers out there that don't follow the C++
> Standard when it comes to default-initialisation. Here's some quick test
> code if anyone would like to try it out. So far, it seems to identify g++
> and VC++ as K++ compilers.

I think I'll give it two or three more years. Till then I'll use what I
suggested :-). BTW, what does K++ stand for?

W

0
Reply w_erasm (159) 11/9/2006 1:47:57 PM

Frederick Gotham wrote:
> It seems there's quite a few compilers out there that don't follow the C++
> Standard when it comes to default-initialisation. Here's some quick test
> code if anyone would like to try it out. So far, it seems to identify g++
> and VC++ as K++ compilers.

BTW, I wrote these utils for K++ compilers :-). Of course, I got the
ideas all over the show... Array::zero is basically the one I use.
Unfortunately, I still have to handle mutliple subscript arrays.

namespace Array{

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Description:
// Returns the first item in an array - for use with algorithms.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
template <class T, std::size_t N>
T* begin( T (&array)[N] )
{
  return &array[0];
}
template <class T, std::size_t N>
const T* begin( const T (&array)[N] )
{
  return &array[0];
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Description:
// Returns the last item in an array - for use with algorithms.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
template <class T, std::size_t N>
T* end( T (&array)[N] )
{
  return (&array[0]+N);
}
template <class T, std::size_t N>
const T* end( const T (&array)[N] )
{
  return (&array[0]+N);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Description:
// Initialises an array over its entire range with <value>.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
template <class T, std::size_t N>
void fill( T (&array)[N], const T& value )
{
  std::fill( begin( array ), end( array ), value );
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Description:
// Zero initialises an array over its entire range. Mostly applicable
to arrays of
// scalar types.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
template <class T, std::size_t N>
void zero( T (&array)[N] )
{
  std::fill( begin( array ), end( array ), T() );
}

}//namespace Array


Regards,

Werner

0
Reply w_erasm (159) 11/9/2006 2:17:23 PM

werasm wrote:
> Frederick Gotham wrote:
>> It seems there's quite a few compilers out there that don't follow
>> the C++ Standard when it comes to default-initialisation. Here's
>> some quick test code if anyone would like to try it out. So far, it
>> seems to identify g++ and VC++ as K++ compilers.
>
> I think I'll give it two or three more years. Till then I'll use what
> I suggested :-). BTW, what does K++ stand for?

'Krapp'?  'Kaput'?  Oh, I know... 'Kompiler'! (not really a compiler,
but klouz). 


0
Reply v.Abazarov (13255) 11/9/2006 2:19:31 PM

Victor Bazarov wrote:
> werasm wrote:
> > Frederick Gotham wrote:
> >> It seems there's quite a few compilers out there that don't follow
> >> the C++ Standard when it comes to default-initialisation. Here's
> >> some quick test code if anyone would like to try it out. So far, it
> >> seems to identify g++ and VC++ as K++ compilers.
> >
> > I think I'll give it two or three more years. Till then I'll use what
> > I suggested :-). BTW, what does K++ stand for?
>
> 'Krapp'?  'Kaput'?  Oh, I know... 'Kompiler'! (not really a compiler,
> but klouz).

At least now I know how things should work :-). I thought I was reading
that standard wrong. W

0
Reply w_erasm (159) 11/9/2006 2:42:40 PM

9 Replies
30 Views

(page loaded in 0.126 seconds)


Reply: