Worrying Prevalence of K++ Compilers

  • Thread starter Frederick Gotham
  • Start date
F

Frederick Gotham

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;
}
 
V

Victor Bazarov

Frederick said:
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
 
F

Frederick Gotham

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.
 
V

Victor Bazarov

Frederick said:
Victor Bazarov:



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




It failed on Version 3.4.2 for me.




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.
 
J

Jim Langston

Frederick Gotham said:
Victor Bazarov:



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).
 
W

werasm

Frederick said:
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
 
W

werasm

Frederick said:
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
 
V

Victor Bazarov

werasm said:
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).
 
W

werasm

Victor said:
'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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top