470,870 Members | 1,418 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

regarding typecasting

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 help me
out in knowing, why this problem is happening.

Appreciate your help in this regard.

Thanks,
Vikas.
Jun 27 '08 #1
11 1404
Please replace typecast with typdef.

vikas

On Jun 5, 6:09*pm, venkat <venkatavi...@gmail.comwrote:
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 help me
out in knowing, why this problem is happening.

Appreciate your help in this regard.

Thanks,
Vikas.
Jun 27 '08 #2
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 help 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
Jun 27 '08 #3
On Jun 5, 6:15*pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
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 help 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
Jun 27 '08 #4
Hi Kai-Uwe,

Thanks for replying.

Does that means, i have char and signed char are different in c++,
which is not the case in C language.
vikas

On Jun 5, 6:15*pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
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 help 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
Jun 27 '08 #5
venkat wrote:
Hi Kai-Uwe,

Thanks for replying.

Does that means, i have char and signed char are different in c++,
which is not the case in C language.
a) Please don't top post.

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.
Best

Kai-Uwe Bux
Jun 27 '08 #6
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

Jun 27 '08 #7
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
Jun 27 '08 #8
On Thu, 5 Jun 2008 06:20:42 -0700 (PDT), venkat
<ve**********@gmail.comwrote:
>On Jun 5, 6:15*pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
>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 help 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.
Jun 27 '08 #9
On Thu, 5 Jun 2008 06:20:42 -0700 (PDT), venkat
<ve**********@gmail.comwrote in comp.lang.c++:
On Jun 5, 6:15*pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
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 help 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
Jun 27 '08 #10
On Thu, 5 Jun 2008 06:42:57 -0700 (PDT), venkat
<ve**********@gmail.comwrote in comp.lang.c++:
Hi Kai-Uwe,

Thanks for replying.

Does that means, i have char and signed char are different in c++,
which is not the case in C language.
That is the second time you have said this about C, and you are just
as wrong both times.

char, signed char, and unsigned char are different types in both C and
C++. char will have the same representation and range of either
signed or unsigned char, in every C and C++ implementation, but it is
a different type.

It may just happen to be that char is signed on the C implementations
you are familiar with, but there are other implementations of both C
and C++ where char is unsigned.

In any case, in both languages, there is no explicit conversion
between pointer to char, pointer to signed char, and pointer to
unsigned char.

If you have a C compiler that allows you to assign one of these
pointers to a pointer to either of the other types, either it is
broken or you are not invoking it in standard conforming mode.

--
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
Jun 27 '08 #11
On Jun 5, 3:20 pm, venkat <venkatavi...@gmail.comwrote:
On Jun 5, 6:15 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
venkat wrote:
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 help 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.
No difference between C and C++ here. "signed char" and "char"
are two different types in both languages, and neither language
has implicit conversions between "signed char*" and "char*".
Do i have to have a
"typedef char sint;" , for making the code to work.
Why do you want a typedef to begin with?

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orient�e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34
Jun 27 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Kapil Khosla | last post: by
7 posts views Thread by Nicolay Korslund | last post: by
63 posts views Thread by andynaik | last post: by
11 posts views Thread by Vinod Patel | last post: by
4 posts views Thread by vivekian | last post: by
12 posts views Thread by bwaichu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.