Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Is there any difference of g++ 3.4.3 and g++ 3.3.4 ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Carfield Yim  
View profile  
 More options Jun 30 2009, 7:45 am
Newsgroups: comp.lang.c++
From: Carfield Yim <carfi...@gmail.com>
Date: Tue, 30 Jun 2009 04:45:29 -0700 (PDT)
Local: Tues, Jun 30 2009 7:45 am
Subject: Is there any difference of g++ 3.4.3 and g++ 3.3.4 ?
HI, my source code was compiled ok in g++ 3.3.4 . But when I try to
use 3.4.3 to compile, I get the following error:

Utility.h: In constructor `Buffer<size>::Buffer(const char*)':
Utility.h:174: error: `buffer' undeclared (first use this function)
Utility.h:174: error: (Each undeclared identifier is reported only
once for each function it appears in.)
Utility.h:176: error: no matching function for call to `strchr(<type
error>, char)'
/usr/include/iso/string_iso.h:130: note: candidates are: char* strchr
(const char*, int)
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/
3.4.3/cstring:107: note:                 char* std::strchr(char*, int)
Utility.h: In member function `Buffer<size>& Buffer<size>::operator+
(const char*)':
Utility.h:183: error: `buffer' undeclared (first use this function)
Utility.h: In member function `Buffer<size>& Buffer<size>::operator+
(char)':
Utility.h:258: error: `buffer' undeclared (first use this function)
Utility.h: In member function `Buffer<size>& Buffer<size>::operator+
(int)':
Utility.h:271: error: `buffer' undeclared (first use this function)
Utility.h: In member function `Buffer<size>& Buffer<size>::operator+
(long int)':
Utility.h:287: error: `buffer' undeclared (first use this function)
Utility.h: In member function `Buffer<size>& Buffer<size>::operator+
(short int)':
Utility.h:303: error: `buffer' undeclared (first use this function)
Utility.h: In member function `Buffer<size>& Buffer<size>::operator+
(double)':
Utility.h:319: error: `buffer' undeclared (first use this function)
Utility.h: In member function `int Buffer<size>::length()':
Utility.h:329: error: `buffer' undeclared (first use this function)

I've checked the source code, look like "buffer" is declared at the
very beginning, can you help to suggest were is the problem? And what
is the hint of checking this problem?

Here is the source code:

#ifndef _Utility_h
#define _Utility_h

extern "C" {
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

}

// quick and dirty template string class (unfortunately non-standard!)

template<int size>
class String {
public:
    char buffer[size + 1];

    String() { buffer[0] = '\0';}

    String(const char *from) {
//        strncpy(buffer, from, size);
        int smaller = (size < strlen(from)) ? size : strlen(from);
        strncpy(buffer, from, smaller);
        buffer[smaller] = '\0';
    }

    String(const int from) {
        memset(buffer, '\0', size);
        sprintf(buffer, "%d", from);
    }

    // assignment from String<size>

    String& operator=(const String& from) {
        int smaller = (size < from.getSize())? size : from.getSize();
        strncpy(buffer, from.buffer, smaller);
        buffer[smaller] = '\0';
        return *this;
    }

    // assignment from const char *

    String& operator=(const char *from) {
//        strncpy(buffer, from, size);
        if (!from) {
            buffer[0] = '\0';
            return *this;
        }
        int smaller = (size < strlen(from)) ? size : strlen(from);
        strncpy(buffer, from, smaller);
        buffer[smaller] = '\0';
        return *this;
    }

    // assignment from int&

    String& operator=(const int& from) {
        memset(buffer, '\0', size);
        sprintf(buffer, "%d", from);
        return *this;
    }

    // assignment from short&

    String& operator=(const short& from) {
        memset(buffer, '\0', size);
        sprintf(buffer, "%d", from);
        return *this;
    }

    // assignment from long&

    String& operator=(const long& from) {
        memset(buffer, '\0', size);
        sprintf(buffer, "%d", from);
        return *this;
    }

    // assignment from double&

    String& operator=(const double& from) {
        memset(buffer, '\0', size);
        sprintf(buffer, "%f", from);
        return *this;
    }

    // comparison to String<size>&

    int operator==(const String& to) const {
                // JK 990329 - Compare null-terminated string rather than
                //             whole block of memory
        // return !memcmp(buffer, to.buffer, size);
        return !strncmp(buffer, to.buffer, size);
    }

    // comparison to String<size>&

    int operator!=(const String& to) const {
                // JK 990329 - Compare null-terminated string rather than
                //             whole block of memory
        // return memcmp(buffer, to.buffer, size) != 0;
        return strncmp(buffer, to.buffer, size) != 0;
    }

    // comparison to const char *

    int operator==(const char *to) const {
        return !strcmp(buffer, to);
    }

    // comparison to const char *

    int operator!=(const char *to) const {
        return strcmp(buffer, to);
    }

//    operator const char*() const { return buffer; }

    operator char *() const { return (char *)buffer; }

    operator int() const { return atoi(buffer); }

    char *operator*() const { return (char *)buffer; }

    int getSize() const{ return size; }

};

// Buffer is used only for generating the ISQL output.

template<int size>
class Buffer : public String<size> {
    char *end;
public:
    Buffer(const char *from = "") {
        strncpy(buffer, from, size);
        buffer[size] = '\0';
        end = strchr(buffer, '\0');
    }

    // append operator from const char *

    Buffer& operator+(const char *from) {
        int length = strlen(from);
        if (end + length <= buffer + size) {
            memcpy(end, from, length);
            end += length;
        } else {
            memcpy(end, from, buffer + size - end);
            end = buffer + size;
        }
        return *this;
    }

    Buffer& operator+=(const char *from) {
        int length = strlen(from);
        if (end + length <= String<size>::buffer + size) {
            memcpy(end, from, length);
            end += length;
        } else {
            memcpy(end, from, String<size>::buffer + size - end);
            end = String<size>::buffer + size;
        }
        return *this;
    }

    // append operator from char

    Buffer& operator+=(char from) {
        if (from == '\0') {
            return *this;
        }
        if (end + 1 <= String<size>::buffer + size) {
            end[0] = from;
            end += 1;
        }
        return *this;
    }

    // append operator from int

    Buffer& operator+=(int i) {
        char from[16];
        sprintf(from, "%d", i);
        int length = strlen(from);
        if (end + length <= String<size>::buffer + size) {
            memcpy(end, from, length);
            end += length;
        } else {
            memcpy(end, from, String<size>::buffer + size - end);
            end = String<size>::buffer + size;
        }
        return *this;
    }

    // append operator from double

    Buffer& operator+=(double d) {
        char from[64];
                // JK 990329 - Ouput precision to 9 decimal places
        // sprintf(from, "%f", d);
        sprintf(from, "%.9f", d);
        int length = strlen(from);
        if (end + length <= String<size>::buffer + size) {
            memcpy(end, from, length);
            end += length;
        } else {
            memcpy(end, from, String<size>::buffer + size - end);
            end = String<size>::buffer + size;
        }
        return *this;
    }

    // append operator from char

    Buffer& operator+(char from) {
        if (from == '\0') {
            return *this;
        }
        if (end + 1 <= buffer + size) {
            end[0] = from;
            end += 1;
        }
        return *this;
    }

    // append operator from int

    Buffer& operator+(int i) {
        char from[16];
        sprintf(from, "%d", i);
        int length = strlen(from);
        if (end + length <= buffer + size) {
            memcpy(end, from, length);
            end += length;
        } else {
            memcpy(end, from, buffer + size - end);
            end = buffer + size;
        }
        return *this;
    }

    // append operator from long

    Buffer& operator+(long i) {
        char from[16];
        sprintf(from, "%d", i);
        int length = strlen(from);
        if (end + length <= buffer + size) {
            memcpy(end, from, length);
            end += length;
        } else {
            memcpy(end, from, buffer + size - end);
            end = buffer + size;
        }
        return *this;
    }

    // append operator from short

    Buffer& operator+(short i) {
        char from[16];
        sprintf(from, "%d", i);
        int length = strlen(from);
        if (end + length <= buffer + size) {
            memcpy(end, from, length);
            end += length;
        } else {
            memcpy(end, from, buffer + size - end);
            end = buffer + size;
        }
        return *this;
    }

    // append operator from double

    Buffer& operator+(double d) {
        char from[64];
        sprintf(from, "%.9f", d);
        int length = strlen(from);
        if (end + length <= buffer + size) {
            memcpy(end, from, length);
            end += length;
        } else {
            memcpy(end, from, buffer + size - end);
            end = buffer + size;
        }
        return *this;
    }

    int length() { return end - buffer; }

};

class Date : public String<16> {
    static Date time;
public:
    Date& operator=(const Date& from) {
        String<16>::operator=(from);
        return *this;
    }

    // TODO check that it is fine to leave this out
    //    Date& operator=(const char *& from) {
    //    String<16>::operator=(from);
    //    return *this;
    //}

    Date& operator=(const char *from) {
        String<16>::operator=(from);
        return *this;
    }

    int operator>(const Date& to) const {
        return memcmp(buffer, to.buffer, 16) > 0;
    }

    int operator>=(const Date& to) const {
        return memcmp(buffer, to.buffer, 16) >= 0;
    }

    int operator<(const Date& to) const {
        return memcmp(buffer, to.buffer, 16) < 0;
    }

    int operator<=(const Date& to) const {
        return memcmp(buffer, to.buffer, 16) <= 0;
    }

    int validate() const {
        int yr, mo,
...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pete Becker  
View profile  
 More options Jun 30 2009, 8:00 am
Newsgroups: comp.lang.c++
From: Pete Becker <p...@versatilecoding.com>
Date: Tue, 30 Jun 2009 08:00:40 -0400
Local: Tues, Jun 30 2009 8:00 am
Subject: Re: Is there any difference of g++ 3.4.3 and g++ 3.3.4 ?

Read the FAQ about how to post requests for help. Nobody here wants to
read through three-hundred fifty lines of mostly irrelevant code. Start
cutting things out that don't pertain to the problem. Reduce the code to
a minimal example that still has the problem. If you haven't figured out
what's wrong from doing that, post the minimal example.

Two quick tips, though (probably not relevant to this particular problem):

> #ifndef _Utility_h
> #define _Utility_h

Names that begin with an underscore followed by a capital letter are
reserved to the implementation. Don't use them.

> extern "C" {
> #include <string.h>
> #include <stdlib.h>
> #include <stdio.h>
> }

Don't ever do this. #include directives for standard headers must be at
global scope (in particular, outside any namespace directives and
outside any extern "C" or extern "C++" blocks). That's also a good
policy for any other #include directives.

--
   Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bart van Ingen Schenau  
View profile  
 More options Jun 30 2009, 2:05 pm
Newsgroups: comp.lang.c++
Followup-To: comp.lang.c++
From: Bart van Ingen Schenau <b...@ingen.ddns.info>
Date: Tue, 30 Jun 2009 20:05:42 +0200
Local: Tues, Jun 30 2009 2:05 pm
Subject: Re: Is there any difference of g++ 3.4.3 and g++ 3.3.4 ?

Carfield Yim wrote:
> HI, my source code was compiled ok in g++ 3.3.4 . But when I try to
> use 3.4.3 to compile, I get the following error:

> Utility.h: In constructor `Buffer<size>::Buffer(const char*)':
> Utility.h:174: error: `buffer' undeclared (first use this function)
<snip>

> I've checked the source code, look like "buffer" is declared at the
> very beginning, can you help to suggest were is the problem? And what
> is the hint of checking this problem?

The problem is in the so-called 'two phase name lookup' that is used
when compiling templates. g++ 3.3.4 gets this wrong and g++ 3.4.3 gets
it right.

There are two times that a compiler performs name lookup for names that
occur within a template:
1. When the template code is parsed by the compiler
2. When the template is instantiated

The first time, the compiler tries to resolve all the names that are
apparently not dependent on any of the template parameters. This
includes the name 'buffer'. However, because the base class itself
depends on a template parameter, it is excluded from the search (because
the compiler can't be sure that there will not be a later specialisation
with completely different members).

That is the reason why the compiler is unable to resolve the name
'buffer' to something meaningful.

At the second lookup, all the remaining (dependent) names are resolved
and, because it is known which instantiation of the base class to use,
the base class is also included in the search.
The trick is now to let it be known that 'buffer' is actually a
dependent name and should be looked up in the second phase. This can be
done by explicitly using the member-access notation: this->buffer.

<snip>

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carfield Yim  
View profile  
 More options Jul 2 2009, 7:52 am
Newsgroups: comp.lang.c++
From: Carfield Yim <carfi...@gmail.com>
Date: Thu, 2 Jul 2009 04:52:08 -0700 (PDT)
Local: Thurs, Jul 2 2009 7:52 am
Subject: Re: Is there any difference of g++ 3.4.3 and g++ 3.3.4 ?

Thanks a lot

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »