I am receiving some data from a socket. After that, I want to print a single byte in the received char array. Below is the code that I used: char buf[100]; int i = 0; while (1) { rc = recv(socket_fd, buf, sizeof(buf), 0); if (rc > 0) { printf("Pos
Consider this simple code: class A {} class B extends A {} public class TestClass { public static void main(String args[]) { A[] a, a1; B[] b; a = new A[10]; a1 = a; b = new B[20]; a = b; // 1 b = (B[]) a; // 2 b = (B[]) a1; // 3 } } Look closely at
FAMILY<- c('FAMILYA', 'FAMILYA', 'FAMILYA', 'FAMILYA', 'FAMILYA', 'FAMILYB', 'FAMILYB', 'FAMILYB', 'FAMILYB', 'FAMILYB', 'FAMILYC', 'FAMILYC', 'FAMILYC', 'FAMILYC', 'FAMILYC') CHILDREN<-c('JAKE', 'PETE', 'JASON', 'KEVIN', 'ALFRED','DALE', 'STEVE', '
I'm following this MOOC on OOP in Java and it has presented an example I don't fully understand. In the example, a Book class has been created and they are constructing an 'equals' override method for the Book class. The new equals() method takes a p
I have a class defined as follows: template< typename... > class Base; template< typename T > class Base<T>{ //pure virtual functions dependent on T public: virtual ~Base() = default; }; template< typename... Ts > class Base<Ts.
The method i'm calling accepts List<string>. I need to select what i want from a List listviewItems.Select(x => x.Tag).ToList() But since the Tag itself is an object it won't work because the result is List<object>. I've also tried listview
I do have a "C" function find_register(char *name) which is called from a "C++" routine. The first tip to call it was find_register("%ebx") It results in a warning deprecated conversion from string constant to 'char*' OK, I c
I want to convert an MKMapPoint to a NSValue. In Objective-C i can do it with the following statement: MKMapPoint point = MKMapPointForCoordinate(location.coordinate); NSValue *pointValue = [NSValue value:&point withObjCType:@encode(MKMapPoint)]; How
Is there a difference (and if so what's the underlying principle?) between downcasting variable as! NSString and downcasting variable as NSString!?variable as! NSString is forced downcasting of a variable to NSString and will raise run time error if
Is it safe to convert between voidarg and chararg or between voidarg and fooarg?: typedef int (*voidarg)(void *); typedef int (*chararg)(char *); typedef int (*fooarg)(foo_t *); Or between voidret and charret or between voidret and fooret?: typedef v
Let int a = 0; Then is (int)a an rvalue in standard C++? Different compilers show different results for this code: #include <iostream> using namespace std; void f(int& x) { cout << "l value" << endl; } void f(int&&
I'm often casting query results to user defined types. Consider this simplistic example: test=# create type test_type as (a int, b int); CREATE TYPE test=# create table test_table (a int, b int); CREATE TABLE test=# insert into test_table values (1,2
I got this warning "warning: assignment makes integer from pointer without a cast"! I want to figure out what does it mean? And what i need to change in my fucntion create_rectangle..... Thank you. Any help appreciated struct point { int x; int
I know that floating point variables loose precision while casting. But what I don't understand is, why a cast from a smaller primitive to a bigger one is unprecise but vice versa not. I would understand if it happens from double to float but it's th
I have the following POCO classes public interface IObject { Guid Uid { get; set; } } public class Boo : IObject { public Guid Uid { get; set; } public String Name { get; set; } } public class Foo : IObject { public Guid Uid { get; set; } public Stri
I have JSON data which I want to convert to correct type and then handle it. I'm using MONO and NewtonSoft's JSON library. I.E. JSON and object must match properties 1:1 to convert to right DTO. DTO's have unique properties always. Both Activator.Cre
Disclaimer: I am still learning SQL so I apologize if my question comes off as amateur-ish or is otherwise a very simple answer. I have no formal training. I am teaching myself. The title may be a bit confusing, as I'm not entirely sure how to word t
I need to send an array of 500,000 ints over a socket between two Android devices. Currently, I'm spending a lot of time converting the int[] to a byte[] so that Java's socket will accept it (see my previous question Efficiently send large int[] over
Code: typedef signed short SIGNED_SHORT; //16 bit typedef signed int SIGNED_INT; //32 bit SIGNED_SHORT x; x = (SIGNED_SHORT)(SIGNED_INT) 45512; //or any value over 32,767 Here is what I know: Signed 16 bits: Signed: From −32,768 to 32,767 Unsigned: F
I'v asked these question some time ago: Multiple inheritance casting from base class to different derived class But I'm still not sure I understand the answer. The question is: Is the code below valid? #include <iostream> using namespace std; struct
I always seem to be needing to cast values in the params object in order to perform a .equals but it never feels right. If i use the parseXXX methods I also have to protect myself when the value is empty. It seems like there would be a better way to
I have two types that have the same members, but different names. Is there an easy or standard way to cast between them, or do I have to do some serious hacking with reflection?You could create an interface that describes both of the types. Make each
Which of these options is more optimal? imploding in MySQL $rsFriends = $cnn->Execute('SELECT CAST(GROUP_CONCAT(id_friend) AS CHAR) AS friends FROM table_friend WHERE id_user = '.q($_SESSION['id_user'])); $friends = $rsFriends->fields['friends']; ec
Recently I found a great example of why C-style casts are bad. We start with a following class implementing multiple COM interfaces (I have two for brevity, but there can be ten in real life): class CMyClassInitial : public IInterface1, public IInter
I'll be the first person to tell someone that my code design could use improvement. I can't help but feel that when I have typecasts in my code that its a sign that something needs to be redesigned to remove the typecasts. This question sort of has t
According to the standard (§5.2.11) a const_cast casts away cv-qualifiers (const or volatile). Here's a simple example. First you declare two functions taking a pointer and a reference: class Bar { ... }; void foo_ptr(Bar*); void foo_ref(Bar&); then
It is clear that the T[] array type is not covariant as the elements of a T[] can be set by index. And yet, a U[] can be cast to a T[] without any complaints from the compiler as long as U derives from T. Man[] men = new[] { new Man("Aaron"), ne
When I try to use a static_cast to cast a double* to an int*, I get the following error: invalid static_cast from type 'double*' to type 'int*' Here is the code: #include <iostream> int main() { double* p = new double(2); int* r; r=static_cast<in
I have a object: ExampleClass ex = new ExampleClass(); And: Type TargetType I would like to cast ex to type described by TargetType like this: Object o = (TargetType) ex; But when I do this I get: The type or namespace name 't' could not be found So
I tend to use ArrayLists of structures. It is then very easy to cycle through the list with a foreach. The problem I have is I cant use a foreach to modify the structures contents and have to use a for and messy typecasts. ((dataStructure)files[x]).n