473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Worrying Prevalence of K++ Compilers


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
Nov 8 '06 #1
9 1281
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
Nov 8 '06 #2
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
Nov 8 '06 #3
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.
Nov 8 '06 #4
Frederick Gotham wrote:
>
>>Which g++?

It failed on Version 3.4.2 for me.
Works on 3.4.6 for me.

- J.
Nov 8 '06 #5

"Frederick Gotham" <fg*******@SPAM.comwrote in message
news:2q*******************@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

Nov 9 '06 #6

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

Nov 9 '06 #7

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

Nov 9 '06 #8
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).
Nov 9 '06 #9

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

Nov 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bill Davidson | last post by:
Hi there, Please forgive me for posting this article on multiple groups. Being new in the newsgroups, I was not sure which group would have been appropriate for my question. Sorry. My...
13
by: Derek | last post by:
As I understand it there is a good amount of link compatibility among C compilers. For example, I can compile main.c with GCC and func.c with Sun One and link the objects using either linker (GNU...
0
by: Chris Stephens | last post by:
Low Cost C Compilers ------------------------------------ HI-TECH Software's C compilers are now available to support the ARM, dsPIC, msp430, 8051, PIC 10 to 17, PIC 18 as well as many other...
3
by: Robert | last post by:
I have a number of web projects converted from 1.1 to 2.0 in VS2005. I am methodically seeing the error below: The element 'compilation' has invalid child element 'compilers'. List of...
9
by: Christopher Benson-Manica | last post by:
In your experience, what is the prevalence of "good" C++ (i.e., the code makes full use of solid language features and the STL) versus C++ written in ignorance (or defiance) of one or more key...
12
by: madhura | last post by:
Hello, I have a basic question about compilers. What are the different types of compilers, are they written by different companies, why there are different names of compilers, what is the purpose,...
1
by: dbaGrant | last post by:
I have upgraded an asp.net 1.1 application to asp.net 2.0 using the upgrade wizard in VS2005. The web.config file which worked correctly in 1.1 now has an error that will not allow the application...
8
by: pransri2006 | last post by:
Hi guys! I think all of u know about the designing of compilers. Can any body tell me about the designing of the compilers. And also tell me the difference between the compilers and Interpreter...
30
by: albert.neu | last post by:
Hello! What is a good compiler to use? (for MS Windows, for Linux) Any recommendations?? What's the point of having a C99 standard, if different compilers still produce differing results? ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.