casting

Using javax.tools.ToolProvider from a custom classloader?

It seems to be impossible to use javax.tools.ToolProvider from a custom classloader as required by Ant or Webstart: http://bugs.sun.com/view_bug.do?bug_id=6548428 javax.tools.ToolProvider.getSystemJavaCompiler() loads javax.tools.JavaCompiler into a URLClassLoader whose parent is the system classloader. The API does not seem to allow us...

Casting in the Linq To SQL

I've one interface which has following method signatures: public interface ITag { int M_Id { get; set; } string M_Name { get; set; } } And I have a class that implements the interface above: [Table(Name="News")] public class NewsTag:ITag { [Column(Name="id",isPrimaryKey = true)] public int M_Id { get; set;...

ClassCastException when usign HQL

Hi, See the following mapping public class SomeClass { private Integer someField; } When i call the following query select someField, count(*) from SomeClass inner join OtherClass... group by ... And i proccess the query as follows Map<Integer, Integer> result = new HashMap<Integer, Integer>(); List<Object> objectList = qu...

Arithmetical operations with void* pointers to numerical data.

Hi I am working on small parser and "equation solver" in C, part of this process is to do arithmetical operations on tokens. Each token contains void* pointer to numerical data, and enum, which defines type of data. This is example of the function, which creates new token by adding two others tokens. In order to do so, I need to che...

casting operator - const vs non-const

I have this here code sample: class Number { int i; public: Number(int i1): i(i1) {} operator int() const {return i;} }; What are the implications of removing the const modifier from the casting operator? Does it affect auto casting, and why? ...

Best way to cast a float to an int for arithmetic?

In C#, I am doing something like this: float a = 4.0f; float b = 84.5f; int ans = a * b; However, the compiler states that a cast is required to go from float -> int in assignment. Of course I could probably do this: int ans = (int)a * (int)b; But this is ugly and redundant. Is there a better way? I know in C++ I could do this: in...

Java wrapper classes. Casting.

Is there a name for when you convert a primitive to an object using wrapper classes? Im assuming this is also called casting correct? ...

.NET casting objects

I have an abstract class called user, and 2 sub classes: RegisteredUser & VisitorUser. I have a need to convert a VisitorUser object to a RegisteredUser object - do I use casting to achieve this? If so, how? ...

Most portable and reliable way to get the address of variable in C++

Using & to get an address of a variable can be problematic if the variable type has overloaded operator&(). For example, _com_ptr_ has operator&() overloaded with a side effect of modifying the object. Now I have a complicated set of templates with functions like this: template<class T> void process( const T* object ) { //whatever ...

What's the purpose of boost::detail::addr_impl_ref ?

Inside boost there's boost::detail::addr_impl_ref struct that basically has a constructor accepting a T& reference and an overloaded operator T&() that returns that reference. It is used in the implementation of boost::addressof(): template<class T> T* addressof( T& v ) { return boost::detail::addressof_impl<T>::f( boost::detail::ad...

Why and when is cast to char volatile& needed?

In boost::detail::addressof_impl::f() a series of reinterpret_casts is done to obtain the actual address of the object in case class T has overloaded operator&(): template<class T> struct addressof_impl { static inline T* f( T& v, long ) { return reinterpret_cast<T*>( &const_cast<char&>(reinterpret_cast<const...

Can C# compiler be configured to give warning when explicit cast may cause data loss?

Is there a way to configure the VS2008 C# compiler to give a warning for code like this: Int64 x = 123456789000; Int32 y = (Int32)x; ...

Converting this varchar to a decimal with the appropriate decimal point?

Hi everyone, I've been playing with cast()s and such with this and can't seem to get things to work. I have a varchar string that's 18 characters long that I'd like to convert or cast to a decimal, with five decimal places. So for instance, this string: 00000001987600130 Would become 19876.00130 It's the case that I'll always have ...

Different Cast Types in C#

Possible Duplicates: Casting: (NewType) vs. Object as NewType Why is the C# as operator so popular? Hey, I know this may be a silly question but this doubt came to me today. What is the difference between doing String text = (String) variable; and String text = variable as String; ? ...

Serialize superclass of object in Java

I am looking for a way to serialize a class in Java into it's superclass, and then convert it to a byte array and send it over a network. Here is an example: class SuperClass { public int number1; } class SubClass extends SuperClass { public int number2; } I don't think it's possible to simply cast an object of SubClass into...

Confused on C++ casting

I have been reading a lot about C++ casting and I am starting to get confused because I have always used C style casting. I have read that C style casting should be avoided in C++ and that reinterpret_cast is very very dangerous and should not be used whenever there is an alternative. On the contrary to not using reinterpret_cast, I hav...

How to convert object which receives image in bytes into actual image?

I am developing smart device application in C#. In that I am calling the web services. The web service method return google map. The return type of the method is object. The object contains the image in byte format. The object conatins the image in base64binary format. I need to display the actual image in my application. What type of ca...

How to convert byte array contained in object to actual image?

I am developing smart device application in C#. In that I am calling the web services. The web service method return google map. The return type of the method is object. The object contains the image in byte format. The object conatins the image in base64binary format. In object I am not getting the string. In object I am getting the by...

Need clarifications in C-style, reinterpret, and const casts

Am I right in assuming that C-style casts (which are discouraged) are nothing but reinterpret_casts? Using the latter is visually striking and easy to search when looking for nasty casts, and hence it's recommended over C-style casts? If casting away const using const_cast and writing to a originally const object is undefined, what is t...

How to cast a void* to int in 64-bit platforms, using C?

I am a linguist in charge of a C program, so please excuse me if the answer is obvious. I have the following code: typedef struct array_s { (...) void **value; } array_t; typedef array_t *array_pt; array_pt array_new (int size) { (...) array->value = (void **)malloc(size*sizeof(void *)); } void* array_get (array_pt arr, int i)...