Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 8th, 2008, 11:32 AM   #1
kurt
Programmer
 
Join Date: Oct 2005
Posts: 68
Rep Power: 3 kurt is on a distinguished road
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
kurt is offline   Reply With Quote
Old Jan 8th, 2008, 12:41 PM   #2
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
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.
Narue is offline   Reply With Quote
Old Jan 8th, 2008, 2:52 PM   #3
kurt
Programmer
 
Join Date: Oct 2005
Posts: 68
Rep Power: 3 kurt is on a distinguished road
Re: Do we need casting to match void * to char *

Quote:
Originally Posted by Narue View Post
>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.
Hm, I guess I can accept casting is need.

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.
kurt is offline   Reply With Quote
Old Jan 8th, 2008, 4:49 PM   #4
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
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.
Narue is offline   Reply With Quote
Old Jan 8th, 2008, 5:55 PM   #5
Salem
Programmer
 
Join Date: Nov 2007
Posts: 33
Rep Power: 0 Salem is on a distinguished road
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.
Salem is offline   Reply With Quote
Old Jan 8th, 2008, 6:08 PM   #6
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,039
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: Do we need casting to match void * to char *

Quote:
Originally Posted by kurt
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.
If this is on the job, then you should point out it's broken code. If you or the employer has a copy of the C++ standard, or even any reputable C++ books, you should be able to make this case.

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
lectricpharaoh is offline   Reply With Quote
Old Jan 8th, 2008, 6:48 PM   #7
kurt
Programmer
 
Join Date: Oct 2005
Posts: 68
Rep Power: 3 kurt is on a distinguished road
Re: Do we need casting to match void * to char *

Quote:
Originally Posted by lectricpharaoh View Post
If this is on the job, then you should point out it's broken code. If you or the employer has a copy of the C++ standard, or even any reputable C++ books, you should be able to make this case.

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.
Haha. A good one

Anyway, you guys are right. It was meant for C, and using the C instead of C++ compiler worked.

Thanks guys!
kurt is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC