![]() |
|
|
|
#1 |
|
On Tue, 13 Jul 2004 12:59:59 +0530, hack_tick <> wrote:
> hi there > i m trying to convert (viod *) data to (unsigned char) using > reinterpret_cast as following > > void *aData; // some data already provided > > unsigned char c = reinterpret_cast<unsingned char>(aData); > > and the gcc is giving me the following error > > ------------------------------------------------- > reinterpret_cast from > `void*' to `unsigned char' loses precision > ------------------------------------------------- > > is this what i m doing is valid Standard C++ ??? > > I have kept settings to treat all warning as Errors, so this is giving me > error > > any suggestions ?? > Converting void* to unsigned char is a completely meaningless thing to do. As the warning states, void* is four bytes (probably) and unsigned char is one byte, so you are losing information. Are you sure you didn't mean to convert to unsigned char*? That would make a lot more sense. john John Harrison |
|
|
|
|
#2 |
|
Posts: n/a
|
hi there
i m trying to convert (viod *) data to (unsigned char) using reinterpret_cast as following void *aData; // some data already provided unsigned char c = reinterpret_cast<unsingned char>(aData); and the gcc is giving me the following error ------------------------------------------------- reinterpret_cast from `void*' to `unsigned char' loses precision ------------------------------------------------- is this what i m doing is valid Standard C++ ??? I have kept settings to treat all warning as Errors, so this is giving me error any suggestions ?? hack_tick |
|
|
|
#3 |
|
Posts: n/a
|
"hack_tick" <> wrote in message news:... > hi there > i m trying to convert (viod *) data to (unsigned char) using > reinterpret_cast as following > > void *aData; // some data already provided > > unsigned char c = reinterpret_cast<unsingned char>(aData); > > and the gcc is giving me the following error reinterpret_cast means like telling the compiler that I know better than you here, just carry out what I am saying. That's unsafe and compiler warns you here that it could be that the destination type is not big enough to hold the source value. reinterpret_cast is very much standard C++. Sharad Kala |
|
|
|
#4 |
|
Posts: n/a
|
hi there
"John Harrison" <> wrote in message news [..] > Converting void* to unsigned char is a completely meaningless thing to do. > As the warning states, void* is four bytes (probably) and unsigned char is > one byte, so you are losing information. > > Are you sure you didn't mean to convert to unsigned char*? That would make > a lot more sense. opps !! actually my mistake, it was (unsigned char *), sorry and thankx for making me realize that hack_tick |
|
|
|
#5 |
|
Posts: n/a
|
hack_tick wrote:
> hi there > "John Harrison" <> wrote in message > news > [..] > >>Converting void* to unsigned char is a completely meaningless thing to do. >>As the warning states, void* is four bytes (probably) and unsigned char is >>one byte, so you are losing information. >> >>Are you sure you didn't mean to convert to unsigned char*? That would make >>a lot more sense. > > > opps !! actually my mistake, it was (unsigned char *), sorry and thankx for > making me realize that > I believe that you can use static_cast<> to cast a void* into any-other-type* red floyd |
|
|
|
#6 |
|
Posts: n/a
|
hi there
"red floyd" <> wrote in message news:ipMIc.10080$ m... [..] > I believe that you can use static_cast<> to cast a void* into > any-other-type* yup we can, i was doing all in hurry and forgt the actual data it was containing(address) thanks for your reply hack_tick |
|
|
|
#7 |
|
Posts: n/a
|
hack_tick wrote:
> hi there > "red floyd" <> wrote in message > news:ipMIc.10080$ m... > [..] > >>I believe that you can use static_cast<> to cast a void* into >>any-other-type* > > > yup we can, i was doing all in hurry and forgt the actual data it was > containing(address) > > thanks for your reply > > just to add , reinterpret cast is best when you try to convert an integer to a pointer. ( assuming the integer contains a valid address). It is no doubt dangerous, ( and not portable, to add ) , but assuming you know what you are doing , then it is best used in scenarios to convert an integer to a pointer. HTH - Karthik. Karthik |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dial Up Problem | smackedass | A+ Certification | 3 | 02-02-2007 11:59 PM |
| Re: Virus Problem ** Help!** | David BlandIII | A+ Certification | 1 | 03-02-2004 06:00 PM |
| Pioneer DVR3100S problem with Satellite receiver Samsung DCR 9500 | Fredrik Bengtsson | DVD Video | 0 | 12-12-2003 02:32 PM |
| Re: Serious Computer Problem | hootnholler | A+ Certification | 1 | 11-24-2003 12:18 PM |
| Re: Serious Computer Problem | Bret | A+ Certification | 0 | 11-19-2003 12:51 AM |