Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > int to *char

Reply
Thread Tools

int to *char

 
 
Rolf Magnus
Guest
Posts: n/a
 
      07-07-2003
Unforgiven wrote:

> For instance, say we have a class A, and a class B : A, and A *pa and
> B *pb;
>
> pa = (A*)pb; // up-cast B* to A*
>
> This has the desired result. However, if we later change the type of
> pb or pa, or change B so it doesn't inherit from A anymore, the above
> code still compiles and runs but has a completely undesirable effect
> (it would do the same as a reinterpret_cast now). Had we written:
>
> pa = static_cast<A*>(pb);
>
> The code wouldn't have compiled anymore after such changes.
>
> (and of course for downcasts dynamic_cast is even better)
>
> If that wasn't (part of) the rationale behind static_cast, it's a
> bloody nice side-effect.


AFAIK, that just is the rationale. The idea is to have more fine-grained
control about the actual conversion. A C style cast does the same as
any combination of static_cast, const_cast and reinterpret_cast that
would be needed for the specific combination of types. So you can also
easily cast away constness with it by accident.

 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      07-07-2003
Dhruv wrote:

> On Sun, 06 Jul 2003 07:12:39 +0100, John Harrison wrote:
>
>>>
>>> /* I'm not sure if this is standard (some people have been saying
>>> it's

>> not,
>>> that they couldn't find the function) */
>>>
>>> int a;
>>> // fill a with the number here
>>> char* chr = new char[21]; // size to at least 1 more than you
>>> need it
>>> itoa(a, chr, 10); // 10 means decimal format, 2
>>> would mean binary, etc.
>>>

>>
>> Most certainly is not standard.
>>

>
> Whoa!!! I spent sooooo much time searching each header to find out
> where this function is. I had practically #included the whole C
> library, to find it, but could not just to find out that it's
> non-stadard, and that's why it wasn't there. No wonder, the glibc
> documentation did not have any information on it.
>
> -Dhruv.
>
> ps: Is there any place I can check whether a function is standard or
> not?


The standard?
Also if you're on a un*x like operating system, the man page of the
function should tell you if that function belongs to any standard. On
other systems, there is probably similar information in the
compiler/library documentation.

 
Reply With Quote
 
 
 
 
Dhruv
Guest
Posts: n/a
 
      07-18-2003
On Mon, 07 Jul 2003 22:36:06 +0200, Rolf Magnus wrote:

[snip]......

>
> The standard?
> Also if you're on a un*x like operating system, the man page of the
> function should tell you if that function belongs to any standard. On
> other systems, there is probably similar information in the
> compiler/library documentation.


Yes But, most of the times, the documentaion on Linux is pretty poor
with this Red Hat distro. that I have, that I've come not to trust it any
more for checking if a function exists or not. I should get a C standard
describibg the functions in the C standard library. RIght now I'm usign
the glibc documentation (postscript) for checking the existence of a
function.

-Dhruv.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why is int a[0] not allowed, but int* a = new int[0] is? haijin.biz@gmail.com C++ 9 04-17-2007 09:01 AM
Difference between int i, j; and int i; int j; arun C Programming 8 07-31-2006 05:11 AM
int a[10]; int* p=(int*)((&a)+1); But why p isn't equal to ((&a)+1)? aling C++ 8 10-20-2005 02:42 PM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments