![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 68
Rep Power: 3
![]() |
Do we need casting to match void * to char *
Why is it that the compiler complains "invalid conversion from void * to char*" when I do not cast it? Isn't void* supposed to be generic?
I have a bunch of files from another person which I am not allowed to edit, and he/she does not cast them. He/she argues that they are compatible without casting and it should work. Is it a compiler specific thing, where I should be setting some flags for it? Thanks in advance, everyone. Kurt |
|
|
|
|
|
#2 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
Re: Do we need casting to match void * to char *
>Isn't void* supposed to be generic?
Yes, but that doesn't mean C++ allows an automatic conversion like C. You still have to cast it.
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#3 | |
|
Programmer
Join Date: Oct 2005
Posts: 68
Rep Power: 3
![]() |
Re: Do we need casting to match void * to char *
Quote:
But are there any compiler flags that can solve this? I've check the compiler manual, no such thing. So I'm wondering if there are common practice that does not cast it but still manage to compile. |
|
|
|
|
|
|
#4 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
Re: Do we need casting to match void * to char *
>But are there any compiler flags that can solve this?
Um, there's nothing to solve. Type safety is a fundamental feature of C++.
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Nov 2007
Posts: 33
Rep Power: 0
![]() |
Re: Do we need casting to match void * to char *
> But are there any compiler flags that can solve this?
You mean like use a C compiler to compile C code perhaps? > I have a bunch of files from another person which I am not allowed to edit Why not? If they're really meant to be C++, then they're clearly wrong.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. |
|
|
|
|
|
#6 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,039
Rep Power: 5
![]() |
Re: Do we need casting to match void * to char *
Quote:
If this is an instructor who has given you these files, and forbidden you to edit them, then you should slap them upside the head with a wet fish, and seek another school.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#7 | |
|
Programmer
Join Date: Oct 2005
Posts: 68
Rep Power: 3
![]() |
Re: Do we need casting to match void * to char *
Quote:
Anyway, you guys are right. It was meant for C, and using the C instead of C++ compiler worked. Thanks guys! |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem processing file into a char array | csrocker101 | C++ | 1 | May 8th, 2007 11:50 PM |
| strcat() && char array[10] && stupid! | Kilo | C++ | 3 | May 22nd, 2006 11:30 AM |
| ascii value to char | Eric the Red | Java | 2 | Apr 9th, 2006 7:36 PM |
| Convert char[14] to char * | myName | C++ | 1 | Mar 5th, 2006 8:08 PM |
| Setting value to char pointer element.... | tempest | C | 11 | Oct 5th, 2005 3:22 PM |