|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I am new to c++ programming language. I have written small program , where i pass the char string then , i find out length. find_len( char *str); is the proto type for the function. I did type casting to give new name to char , typedef signed char sint; Then i replaced the function call with find_len(sint *str); when i compiled, i am getting the error saying, invalid conversion from `sint*' to `char*' i am not able to understand, what was the problem?. Please me out in knowing, why this problem is happening. Appreciate your in this regard. Thanks, Vikas. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Please replace typecast with typdef.
vikas On Jun 5, 6:09pm, venkat <venkatavi...@gmail.com> wrote: > Hi, > > I am new to c++ programming language. I have written small program , > where i pass the char string then , i find out length. > > find_len( char *str); is the proto type for the function. > > I did type casting to give new name to char , > > typedef signed char sint; > > Then i replaced the function call with > > find_len(sint *str); > > when i compiled, i am getting the error saying, invalid conversion > from `sint*' to `char*' > > i am not able to understand, what was the problem?. Please me > out in knowing, why this problem is happening. > > Appreciate your in this regard. > > Thanks, > Vikas. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
venkat wrote:
> Hi, > > I am new to c++ programming language. I have written small program , > where i pass the char string then , i find out length. > > find_len( char *str); is the proto type for the function. > > I did type casting to give new name to char , > > typedef signed char sint; Here you give a new name to signed char not to char. Even if char is signed on your implementation, it is still a different type. > Then i replaced the function call with > > find_len(sint *str); > > when i compiled, i am getting the error saying, invalid conversion > from `sint*' to `char*' > > i am not able to understand, what was the problem?. Please me > out in knowing, why this problem is happening. There is no implicit conversion from signed char * to char *. Therefore, the function does not match. Best Kai-Uwe Bux |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Jun 5, 6:15pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
> venkat wrote: > > Hi, > > > I am new to c++ programming language. I have written small program , > > where i pass the char string then , i find out length. > > > find_len( char *str); is the proto type for the function. > > > I did type casting to give new name to char , > > > typedef signed char sint; > > Here you give a new name to signed char not to char. Even if char is signed > on your implementation, it is still a different type. > > > Then i replaced the function call with > > > find_len(sint *str); > > > when i compiled, i am getting the error saying, invalid conversion > > from `sint*' to `char*' > > > i am not able to understand, what was the problem?. Please me > > out in knowing, why this problem is happening. > > There is no implicit conversion from signed char * to char *. Therefore, the > function does not match. > >>>> Does that means, i have char and signed char are different in c++, which is not the case in C language. >>>> Do i have to have a "typedef char sint;" , for making the code to work. > Best > > Kai-Uwe Bux |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Hi
Kai-Uwe Bux wrote: > b) In C++, char and signed char are different types even if char is > signed. They are required to both have size 1 and there are conversions > between them. But they are different types. > > c) I have no idea what is the case in C, which I never learned. They are also different types in C, but I think it's not as visible there. Markus |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
venkat wrote:
> Hi, > > I am new to c++ programming language. I have written small program , > where i pass the char string then , i find out length. Why are you doing this? Is it a training exercise, or something you think you need? There is a standard function strlen() that does what you want. Brian |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Thu, 5 Jun 2008 06:20:42 -0700 (PDT), venkat
<venkatavikas@gmail.com> wrote: >On Jun 5, 6:15pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote: >> venkat wrote: >> > Hi, >> >> > I am new to c++ programming language. I have written small program , >> > where i pass the char string then , i find out length. >> >> > find_len( char *str); is the proto type for the function. >> >> > I did type casting to give new name to char , >> >> > typedef signed char sint; >> >> Here you give a new name to signed char not to char. Even if char is signed >> on your implementation, it is still a different type. >> >> > Then i replaced the function call with >> >> > find_len(sint *str); >> >> > when i compiled, i am getting the error saying, invalid conversion >> > from `sint*' to `char*' >> >> > i am not able to understand, what was the problem?. Please me >> > out in knowing, why this problem is happening. >> >> There is no implicit conversion from signed char * to char *. Therefore, the >> function does not match. >> > > Does that means, i have char and signed char are different in c++, which is not the case in C language. C++, unlike regular C, has strong type checking and doesn't do all forms of implcit conversions. Some types now need to match more precicely than before. If you need to use multiple types for a given function call, you can create multple instances of that function with different parameters (which in turn simply type-cast the parameters for use in the main function.) >>>>> Do i have to have a "typedef char sint;" , for making the code to work. > |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Thu, 5 Jun 2008 06:20:42 -0700 (PDT), venkat
<venkatavikas@gmail.com> wrote in comp.lang.c++: > On Jun 5, 6:15pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote: > > venkat wrote: > > > Hi, > > > > > I am new to c++ programming language. I have written small program , > > > where i pass the char string then , i find out length. > > > > > find_len( char *str); is the proto type for the function. > > > > > I did type casting to give new name to char , > > > > > typedef signed char sint; > > > > Here you give a new name to signed char not to char. Even if char is signed > > on your implementation, it is still a different type. > > > > > Then i replaced the function call with > > > > > find_len(sint *str); > > > > > when i compiled, i am getting the error saying, invalid conversion > > > from `sint*' to `char*' > > > > > i am not able to understand, what was the problem?. Please me > > > out in knowing, why this problem is happening. > > > > There is no implicit conversion from signed char * to char *. Therefore, the > > function does not match. > > > > >>>> Does that means, i have char and signed char are different in c++, which is not the case in C language. You are completely. C++ has exactly the same three character types that C has: 1. signed char 2. unsigned char 3. char (or "plain" char) There is no implicit conversion between pointers to these three different types in C either. If your C compiler allows direct assignment from any of these three types to any of the others without a cast, either it is broken or you are not invoking it in standard conforming mode. > >>>> Do i have to have a "typedef char sint;" , for making the code to work. Yes. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://c-faq.com/ comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html |
|
![]() |
| Outils de la discussion | |
|
|