[vox-tech] C - passing chars and pointer to chars

Bill Kendrick nbs at sonic.net
Fri Jun 2 12:35:46 PDT 2006


On Fri, Jun 02, 2006 at 11:31:43AM -0400, Peter Jay Salzman wrote:
> Apparently, there's no problem assigning the different chars to each other.
> The compiler does the automatic conversion:

Yep!

I've been reading Thinking in C++, to ramp up on C++ knowledge for work,
and this is discussed.

In C++...

  A static_cast is used for all conversions that are well-defined.
  These include "safe" conversions that the compiler would
  allow you to do without a cast and less-safe conversions that are
  nonetheless well-defined.  The types of conversions covered by
  static_cast include typical castless conversions, narrowing
  (information-losing) conversions, forcing a conversion from a void*,
  implicit type conversions, and static navigation of class hierarchies...

it goes on...

  Promoting from an int to a long or float is not a problem because
  the latter can always hold every value that an int can contain.
  Although it's unnecessary, you can use static_cast to highlight these
  promotions.

  Converting back the other way is shown [in an example in the book].
  Here, you can lose data because an int is not as "wide" as a long or
  a float; it won't hold numbers of the same size.  Thus these are called
  narrowing conversions.  The compiler will still perform these, but will
  often give you a warning.  You can eliminate this warning and indicate
  that you really did mean it using a cast.

HTH somehow!

-bill!


More information about the vox-tech mailing list