casting

"Incompatible pointer type" compiler warning for 4th argument of qsort

I'm trying to use the standard library's qsort to sort an array of wide characters: wchar_t a = L'a'; wchar_t a1 = L'ä'; wchar_t b = L'z'; wchar_t chararray[] = {b, a, a1}; length = wcslen(chararray); qsort(chararray, length, sizeof(wchar_t), wcscoll); Now I think the functions involved have these prototypes: int wcscoll(const wch...

using 'is' where the type is defined at runtime

Can anyone help me? I can't figure out what I am doing wrong but it seems like there will be a simple solution: Normally you can use is like this: if (theObject is MyClass) ... but if you want to specify the type it checks for at runtime this doesnt compile Type theType = ... if (theObject is theType) ... I tried doing this: if (...

How can I avoid a InvalidCastException in .NET?

Is there a way to check whether a C# cast will be successful? In some cases; based on how a rendered page is put together; inheriting from different Master Pages, some casts will work and others will not. I am wondering how I can check to see if a cast will be successful or if I just have to catch and handle an invalid cast exception. ...

Remove redundant casts in Java

Hi, I've been generifying some Java code that used lots of casts, and now most of them are redundant and unnecessary. It could be very tedious to inspect all the usages of the code to remove them, so: are there any tools to help to identify (and remove) superfluous casts? Thanks! ...

VB.Net String to double

Why is it that when I convert a string with value "22.882" to double, using Dbl() it loses precision and is converted to 2288.2? I have to use a double since I'm using the constructor of System.Web.UI.WebControls.Unit (see http://msdn.microsoft.com/en-us/library/ctewx7ch.aspx). ...

SQL Server: Having trouble getting correct decimal value after cast

Hello, I'm trying to write a query that gives me a percentage (i.e. something like .885, for example) by dividing 2 aggregate numbers I selected via SUM. But my results are coming out as 0.0 instead of the correct number. So just for reference, starting with 2 queries, I have: SELECT SUM(CASE WHEN Status_ID = 1 AND State_ID = 14 THEN 1...

Converting / Casting an nVarChar with Comma Separator to Decimal

I am supporting an ETL process that transforms flat-file inputs into a SqlServer database table. The code is almost 100% T-SQL and runs inside the DB. I do not own the code and cannot change the workflow. I can only help configure the "translation" SQL that takes the file data and converts it to table data (more on this later). Now that...

java.io.ObjectStreamClass cannot be cast to java.lang.String

java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast to java.lang.String at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:23...

Is it possible to cast in a MongoDB-Query?

When I have two MongoDB documents like this... db.test.insert( {"value" : "10123"} ); db.test.insert( {"value" : "160"} ); The result of a query like: db.test.find({"value" :{$gt : "12"} }); is.. { "_id" : ObjectId("4c6d1b92304326161b678b89"), "value" : "160" } It's obvious, that a string comparison is made, so that my first va...

Problems accessing a variable which is casted into pointer to array of int with ctypes in python.

Hi there, I have C code which uses a variable data, which is a large 2d array created with malloc with variable size. Now I have to write an interface, so that the C functions can be called from within Python. I use ctypes for that. C code: FOO* pytrain(float **data){ FOO *foo = foo_autoTrain((float (*)[])data); return foo; } ...

Generics and casting - cannot cast inherited class to base class

I know this is old, yet I am still not very good with understanding those problems. Can anyone tell me why the following does not work (throws a runtime exception about casting)? public abstract class EntityBase { } public class MyEntity : EntityBase { } public abstract class RepositoryBase<T> where T : EntityBase { } public class MyEn...

Does this NullPointerException refer to getFoos returning null or some problem with the cast from a Collection to an ArrayList?

Why does this line cause a NullPointerException: List<Foo> foos = new ArrayList<Foo>(userDetailsService.getFoos(currentUser)); The getFoos method simply returns a Collection of Foos: public Collection<Foo> getFoos(final String username) I can't tell if the NullPointerException refers to getFoos returning null or some proble...

What is the difference between static and dynamic cast in c++?

Possible Duplicate: Regular cast vs. static_cast vs. dynamic_cast what is difference between static and dynamic cast in c++? ...

How can I split strings into different types (int for numerical values and char for letters)?

For example, I have this string: SMUL 9 A B? How can I get 9 (int type) A (char) and B (char). Possible string may be SMUL 12 A C, so it means their positions in the string is not constant. Further explanation: this is a string inputted by a user for my matrix calculator program. Inputting SMUL "scalar" "matrix-1" "matrix-2" means that ...

weird compiler error when casting in ternary/conditional operator

I'm experiencing unexpected compiler errors with this code: bool b = true; //or false StringBuilder builder = ...; // a string builder filled with content IVersePart vp = b ? (DualLanguageVersePart)builder : (VersePart)builder; Both DualLanguageVersePart and VersePart implement the IVersePart interface. Both DualLanguageVersePart and ...

What is (double (^)(int))foofoo

There is an example on cdecl that goes (double (^)(int))foofoo means cast foofoo into block (int) returning double. What does it mean to cast foofoo into a "block" of int? What does the symbol ^ exactly mean in this context. Usually it is bitwise XOR. ...

Cast uniqueidentifier to binary

Hi. how can i Cast uniqueidentifier to binary in Sql? Thanks. ...

Inline conditional c# - next best solution?

It seems the compiler is not going let this syntax fly. void main() { foo(false?0:""); } void foo(int i) {return;} void foo(string s) {return;} The only other way I can see of fixing this is something as follows: void bar(object o) { if (o is string){//do this} else{//im an int, do this} } Anyone have any better ideas? ...

Cast T parameter in generic method to DateTime

Hello, I have the following (simplified) method: private static string GetStringFromValue<T>(T val) { if (typeof(T) == typeof(DateTime)) { return string.Format("{0}", ((DateTime)val).Year.ToString("0000")); } return string.Empty; } At the cast "(DateTime)val" I get the following error: Cannot cast expressi...

object casting in C#

Possible Duplicate: Casting: (NewType) vs. Object as NewType Just wanted to know which one is faster and what's the difference. MyClass test = someclass as MyClass; or MyClass test = (MyClass)someclass; ...