texmacs-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Texmacs-dev] GCC 3.2 status update


From: Igor V. Kovalenko
Subject: Re: [Texmacs-dev] GCC 3.2 status update
Date: Wed, 27 Nov 2002 00:08:49 +0300
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020809

David Allouche wrote:
On Tue, Nov 26, 2002 at 12:02:26AM +0300, Igor V. Kovalenko wrote:

I have a question that is out of my expertise as I do not have
current C/C++ standard book.

Are you *sure* you do not violate ANSI data type aliasing rules
by deleting a tree data in destroy_tree_rep() ?

If this is indeed a violation than no one can help here from GCC front.
At least not before GCC/3.4 development AFAIK.

Sorry, I really can't get the current standard book :(
Are there any Internet resources?


Sadly the ISO standard for C++ is only available for a price at ANSI
store. For a few american dollars you can get a PDF copy of the
standard.

I bought one some time ago so I had the Book if I want to explain to
some other hacker how crappy is C++ code is ;-)


For memory, here is the relevant code:

    inline tree::~tree () {
      if ((--rep->ref_count)==0) {
        destroy_tree_rep (rep); rep= NULL; } }

    void
    destroy_tree_rep (tree_rep* rep) {
      if (rep->op == STRING)
        delete ((atomic_rep*) ((void*) rep));
      else
        delete ((compound_rep*) ((void*) rep));
    }

Here are the relevant standard excerpts:

  4.1  lvalue to rvalue conversion

15
   If a programm attempts to access the stored value of an object
   through an lvalue of other than one of the following types the
   behavior is undefined [The intent of this list is to specify those
   circumstances in which an object may or may not be aliased]:

   -- the dynamic type of the object,

   -- a cv-qualified version of the dynamic type of the object,

   -- a type that is the signed or unsigned type corresponding to the
      dynamic type of the object,

   -- a type that is the signed or unsigned type corresponding to a
      cv-qualified version of the dynamic type of the object,
-- an aggregate or union type that includes one of the
      aformentioned types among its members (including, recursively, a
      member of a subaggregate or contained union),

   -- a type that is a (possibly cv-qualified) base class type of the
      dynamic type of the object.

   -- a char or unsigned char type.

There might be more, but that is all I found.

The tree destruction code seems to be compliant. But is uses the evil
C-style cast... generally C-style cast should be replaced by more
specific (and safer) operation in C++.


If my english is still not that bad :) I can't find the cast to subclass
type among the listed items... Please correct me.

--
Regards,
Igor V. Kovalenko    mailto: iko at crec dot mipt dot ru





reply via email to

[Prev in Thread] Current Thread [Next in Thread]