g++ typecast complaining too much!
Ok! I have the following program:
Code:
#include <stdio.h> gcc:(line #):cannot convert unsigned char * to char * for argument 1 to strcpy(char *, char *) and then it bails!!! I know there is a command line switch to disable the paranoid typecasting thing... what is it??? |
If you change your string from unsigned char * to char * it'll get ride of the warning. Of you if case it to a char * in the strcpy line it'll stop complaining. I am not sure why you really need to specify it as unsigned anyway if you are truly using it as an ASCII character string.
Btw, is there a particular reason why you are using g++ to compile this? This code is all standard C. gcc -Wall -o blah blah.c didn't report any warnings to me even with string being set as an unsigned char (but g++ did report the errors). |
Thats my problem! It doesn't complain about typecast errors like this in gcc, but when I started using g++ to compile my old programs it complains and won't compile them.
So I just want to know the switch to turn off complaining about typecasting under g++. What is it? Thanks for your time! |
Basically I don't want the following error:
invalid conversion from `char*' to `unsigned char*' |
I have looked through all the switches in the gcc manual for cpp code and I can't find anything that'll turn that off. -Wno-conversion would do it if it wasn't an error, but because it is flaged as an error (at least in my version of gcc - 3.3.3) it won't help you.
I can't say I understand why you would ever want to compile regular C code with g++ instead of gcc....(why deal with potential abi issues if you don't have to?) but anyway.... I might sound like a jacka** here, but if you want to fix the error how about you fix your code? Because technically speaking your code is wrong and you should get that error. Keep in mind C++ is a lot stricter about the languages rules that C is. |
You are right about fixing my code, but technically I am getting quite frusterated. If I do the following for example:
Code:
void thisFuncDoesNothing(char *str) The other thing that sucks is that this problem is not for just char, it will happen if I go int to unsigned int, or visa-versa... it is just getting irretating, thats all. |
its complaining because the function is defined as taking a char *, but you are giving it a unsigned char *
|
if you want the function to work on unsigned char`s just change the
Code:
void thisFuncDoesNothing(char *str) Code:
void thisFuncDoesNothing(unsigned char *str) |
I see what your saying now.
I modified your code a little and made it work. But now that I think of it, I didn't test it with any of the chars from the extended part of the ascii chart (> 127). This code did compile fine and it would allow you to do the math you want to do. Code:
#include <stdio.h> |
Scratch that, it does appear to work ok.
Code:
#include <stdio.h> This is a string: ˙esting... ff 65 73 74 69 6e 67 2e |
Well.... If it can't be done, I guess I will just try to make less typecasting errors :D
Thanks for all your help guys. |
Just a couple of general notes:
_never_ cast the return of malloc unless you're using a really old C compiler that returns char * where the cast can be necessary. use stdlib.h instead of malloc.h which is non-standard. malloc isn't a C++ idiom, is there a particular reason you want to compile a C program as C++? |
Ya, I wasn't even paying attention to that. Malloc returns a void * these days, so you never need to cast it's return value (at least that is the case in stdlib's malloc).
|
All times are GMT -5. The time now is 01:05 PM. |