MESSAGE
DATE | 2016-01-27 |
FROM | Ruben Safir
|
SUBJECT | Subject: [Hangout-NYLXS] Lexical issues in C++
|
Check this out, it might be useful
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ath: reader1.panix.com!panix!goblin1!goblin.stu.neva.ru!feeder2.usenet.farm!feed er.erje.net!2.eu.feeder.erje.net!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!buffer2.nntp.ams1.giganews.com!local2.nntp.ams1.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 24 Dec 2015 17:34:24 -0600 Newsgroups: comp.lang.c++ Subject: Re: Converting from int* to char* From: Paavo Helde References: <0be9ea2b-738b-419f-8d1f-fc1ea862dbde-at-googlegroups.com> Organization: PKI Message-ID: User-Agent: Xnews/5.04.25 Date: Thu, 24 Dec 2015 17:34:25 -0600 Lines: 39 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-cVmeEnU7iysY1aTV/ojsRsvl3S1Wl88zLdGnZCVugiWdazHyLOKPtLznvPjhULRDs5bAsBI sNhrn4y3!QmvyjBJBIenedZN5Lm0FyWuG3cS5o7eH/udsIW74d43rbeHaH2l95MylSx9xTNkZC4SLDfPqot4T!czyv182e X-Complaints-To: abuse-at-giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2098 Xref: panix comp.lang.c++:1118257
Paul wrote in news:0be9ea2b-738b-419f-8d1f-fc1ea862dbde-at-googlegroups.com:
> I'm confused about when conversions between types are allowed. > int* z = new int(3); > char* x= (char*)z; //works fine. > > However, if the second line is replaced by char* x = char*(z); I get > "expected primary expression before char" compile error. I was > anticipating that I can cast from int* to char* this way in the same way > that you can cast 5.3 to int by writing int(5.3);
This is a lexical issue, it just does not make sense to multiply a type char with something. Change it to
char* x = reinterpret_cast(z);
or
char* x = (char*)(z);
or
typedef char* charPtr; charPtr x = charPtr(z);
Note that only the first one is really C++.
> If the second line is replaced by char*x = z; I get an error -- "can not > convert from char* to int* in initialization" How could I have know > that such an initialization is illegal, given that the cast of the form > char* x = (char*)z; is ok ?
By reading and understanding the language rules?
hth Paavo
-- So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive http://www.coinhangout.com - coins! http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps, but incompatible with living as a free human being. -RI Safir 2013 _______________________________________________ hangout mailing list hangout-at-nylxs.com http://www.nylxs.com/
|
|