PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > regarding typecasting
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
regarding typecasting

Réponse
 
LinkBack Outils de la discussion
Vieux 05/06/2008, 14h09   #1
venkat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 me
out in knowing, why this problem is happening.

Appreciate your in this regard.

Thanks,
Vikas.
  Réponse avec citation
Vieux 05/06/2008, 14h14   #2
venkat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: regarding typecasting

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.


  Réponse avec citation
Vieux 05/06/2008, 14h15   #3
Kai-Uwe Bux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: regarding typecasting

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


  Réponse avec citation
Vieux 05/06/2008, 14h20   #4
venkat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: regarding typecasting

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


  Réponse avec citation
Vieux 05/06/2008, 17h17   #5
Markus Moll
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: regarding typecasting

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

  Réponse avec citation
Vieux 05/06/2008, 19h25   #6
Default User
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: regarding typecasting

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
  Réponse avec citation
Vieux 05/06/2008, 20h40   #7
Raymond Martineau
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: regarding typecasting

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.

>

  Réponse avec citation
Vieux 06/06/2008, 03h44   #8
Jack Klein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: regarding typecasting

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h06.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,19091 seconds with 16 queries