Worrying Prevalence of K++ Compilers

Discussion in 'C++' started by Frederick Gotham, Nov 8, 2006.

  1. 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
     
    Frederick Gotham, Nov 8, 2006
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Nov 8, 2006
    #2
    1. Advertising

  3. 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
     
    Frederick Gotham, Nov 8, 2006
    #3
  4. 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.
     
    Victor Bazarov, Nov 8, 2006
    #4
  5. Frederick Gotham wrote:
    >
    >>Which g++?

    >
    > It failed on Version 3.4.2 for me.


    Works on 3.4.6 for me.

    - J.
     
    Jacek Dziedzic, Nov 8, 2006
    #5
  6. Frederick Gotham

    Jim Langston Guest

    "Frederick Gotham" <> wrote in message
    news:2qq4h.15790$...
    > 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
     
    Jim Langston, Nov 9, 2006
    #6
  7. Frederick Gotham

    werasm Guest

    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
     
    werasm, Nov 9, 2006
    #7
  8. Frederick Gotham

    werasm Guest

    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
     
    werasm, Nov 9, 2006
    #8
  9. 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).
     
    Victor Bazarov, Nov 9, 2006
    #9
  10. Frederick Gotham

    werasm Guest

    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
     
    werasm, Nov 9, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen Thorne
    Replies:
    1
    Views:
    316
    Jack Diederich
    Aug 30, 2004
  2. geletine

    commercial c compilers vs free c compilers

    geletine, Jul 2, 2006, in forum: C Programming
    Replies:
    33
    Views:
    1,340
  3. Christopher Benson-Manica

    Relative prevalence of "good" C++

    Christopher Benson-Manica, Jan 18, 2006, in forum: C++
    Replies:
    9
    Views:
    405
    Christopher Benson-Manica
    Jan 21, 2006
  4. Neo Geshel

    Prevalence of XHTML?

    Neo Geshel, Apr 16, 2007, in forum: HTML
    Replies:
    33
    Views:
    1,073
    Chris F.A. Johnson
    Apr 24, 2007
  5. Dawid Michalczyk

    prevalence of different JVM versions

    Dawid Michalczyk, Jul 27, 2007, in forum: Java
    Replies:
    14
    Views:
    691
    John W. Kennedy
    Aug 1, 2007
Loading...

Share This Page