Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Is an address change possible by "deconstify/const_cast"?

Thread Tools

Is an address change possible by "deconstify/const_cast"?

Martin Ambuhl
Posts: n/a
      07-10-2005 Removed) wrote:

> How do you think about this code example?

*What* I think about your C++ code example is that it ought not be
posted to comp.lang.c. Please pay attention to what you are doing.
Follow-ups set.
Reply With Quote
Posts: n/a
(E-Mail Removed) wrote:
> > You don't show us an implementation of the deconstify1() function.
> > (I think it was in a previous article, but I'm too lazy to go
> > looking for it.)

> How do you think about this code example?

Very little.

> struct context
> {
> long key;
> char const * name1;
> string const * name2;

You haven't defined 'string'.

> } ctx;
> char* X = (char*) malloc(5);

You should NEVER cast the return from malloc. Where did the magic
number '5' come from?

> if (X)
> {
> strcpy(X, "Test");
> ctx.name1 = X;
> ctx.name2 = new string("check");

'new' is a syntax error. This is c.l.c, not c.l.c++.
> /* Treat it as a constant after the initial assignment */
> if (ctx.name2)
> {
> ctx.key = rand();
> printf("%li: %s", ctx.key, ctx.name1);
> cout << *ctx.name2;

You haven't defined cout. Why do you want to left shift it?
*ctx.name2 is not a suitable argument anyhow.

> {
> string* alias1 = const_cast<string*>(ctx.name2);

More syntax errors. Again, this is c.l.c.

.... snip remainder. F'ups set. c.l.c / c.l.c++ crossposts are
pure foolishness.

"If you want to post a followup via, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
efficient data loading with Python, is that possible possible? Python 10 12-14-2007 04:44 PM
A Paradise DNS address change? What change? There was no change. Tony Neville NZ Computing 7 09-22-2006 01:02 PM
is it possible to possible to create an iterator from a callback interace? C Programming 4 02-21-2006 02:10 PM
XML + XSD: Is it possible to get all possible Values for an Element? Markus Java 1 11-22-2005 02:51 PM
Is an address change possible by "deconstify/const_cast"? C++ 12 07-10-2005 04:11 PM