473,385 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1535
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kapil Khosla | last post by:
Hi, I have been trying to understand this concept for quite sometime now somehow I am missing some vital point. I am new to Object Oriented Programming so maybe thats the reason. I want to...
7
by: Nicolay Korslund | last post by:
Hi! I'm having a little trouble with the typecast operator, can anybody help me with the rules for when the this operator is invoked? In the class 'Test' in the code below, the typecast operator...
2
by: Arun Prasath | last post by:
Hi all, I have the following question regd pointer typecasting. Is the following type of pointer typecasting valid? #define ALLOC(type,num) ((type *)malloc(sizeof(type)*num)) /*begin...
63
by: andynaik | last post by:
Hi, Whenever we type in this code int main() { printf("%f",10); } we get an error. We can remove that by using #pragma directive t direct that to the 8087. Even after that the output is...
11
by: Vinod Patel | last post by:
I have a piece of code : - void *data; ...... /* data initialized */ ...... struct known_struct *var = (struct known_struct*) data; /*typecasting*/ How is this different from simple...
3
by: jdm | last post by:
In the sample code for the SortedList class, I see the use of a string typecasting macro consisting of a single letter "S". i.e.: Sortedlist->Add(S"Keyval one", S"Item one"); Now I have...
16
by: Abhishek | last post by:
why do I see that in most C programs, pointers in functions are accepted as: int func(int i,(void *)p) where p is a pointer or an address which is passed from the place where it is called. what...
4
by: vivekian | last post by:
Hi, This is the part of the code am trying to compile to : void Server::respondToClient ( std::string response ) { .... .... if ((numbytes = sendto ( sockFd_ , response , sizeof(response)...
1
by: ramakanta.sinha | last post by:
Hi, While typecasting an integer to (void *) the following warning is found. warning: cast to pointer from integer of different size. This is the line where typecasting is done. fld->base...
12
by: bwaichu | last post by:
What is the best way to handle this warning: warning: cast from pointer to integer of different size I am casting in and out of a function that requires a pointer type. I am casting an...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.