To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 19
18  |  20
Subject: 
Re: Compiling the compiler
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Sat, 6 Mar 1999 02:04:37 GMT
Viewed: 
2418 times
  
In article <dbaum-0503990136590001@max4k-2-36.chi-tcg.enteract.com>,
dbaum@spambgoneenteract.com (Dave Baum) wrote:

In article <4.1.19990304102818.00a9bac0@mail.connect.net>, Joel Shafer
<joel@connect.net> wrote:

delete[] outputFile;
nqc/nqc.cpp(433) : error C2664: 'delete' : cannot convert parameter 1 from
'const char *' to 'void *'
- as the error message indicates outputFile is defined as const char *
can I just cast it to void *?


Yes, a cast should be fine.

Offhand, this may actually be a violation of constness (which means I
should change the source) that Metrowerks and gcc are not catching.  I'll
have to check the C++ spec.


I've checked into this a little further.  It comes down to something like
the following:

void foo(const char *p)
{
   delete p;
}

On one hand, this is conceptually a violation of "constness" as a caller
to foo() wouldn't know that the object pointed to was actually going to be
altered (destroyed!).  On the other hand, there are some cases where
implementors would need to delete const objects (consider container
classes of const objects that use copy-in/copy-out semantics).

The C++ standards committee decided to make const pointers to a delete
expression valid:

[Note:  a  pointer  to  a  const  type can be the operand of a delete-
  expression;  it  is  not  necessary  to  cast   away   the   constness
  (_expr.const.cast_) of the pointer expression before it is used as the
  operand of the delete-expression.  ]

I'll change the code anyway since I personally think deleting const
pointers is ugly.

Dave

--
reply to: dbaum at enteract dot com



Message is in Reply To:
  Re: Compiling the compiler
 
(...) What file are you compiling when you get this error? I think the fix is to include "Symbol.h" before the array templates get instantiated, but it is curious that neither Metrowerks nor gcc complain. (...) Yes, a cast should be fine. Offhand, (...) (26 years ago, 5-Mar-99, to lugnet.robotics.rcx.nqc)

5 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR