prints a single byte after character typing

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

Casting and heritage in Java

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

Reshape the data frame to have the 2 best values

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', '

Casting an object to a subset of its bases

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.

What is the difference between two cast 'char *' in c ++

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

Convert MKMapPoint to NSValue in Swift

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

Type downcasting in Swift

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 these function pointers in C?

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

Is the result of a distribution a value?

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&&

Why is the float double, imprecise, double so as not to float?

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

Convert the framed object to typeof (object)

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

How to dynamically convert JSON to the right DTO class?

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

Convert or Cast VARCHAR to INT; Update column

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

c ++ at runtime if the object implements the interface

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

A more elegant way to launch in the groovy base

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

Casting between similar types in C #

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

Implosion in PHP vs implosion in MySQL - which uses less cpu?

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

What are the harsh examples showing that C style casts are bad?

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

Are typecasts a badly designed code sign?

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

Why does const_cast need to indicate what you use?

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

How is U [] castable in T []?

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

C ++: impossible to static_cast from double * to int *

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

How to convert an object to the type described by Type class?

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

Edit content in foreach

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