I've seen the following a few times lately:
function foo(array $arg = NULL) { ... }
My question being why make the default of $arg NULL when it will be just cast into an array? Why not do:
function foo(array $arg = array()) { ... }
I know it doesn't really make much difference--it's mostly just reading code--but why encourage PHP...
I was wondering, why can't there be a void data type that is not a pointer?
Surely you could get past the whole determined size thing by having
void4
void8
void32
And then only being allowed to 'cast' a void data type to another class if its size is equal or under to the classes size.
Is there something that I'm missing, or does the...
Hello!
I'm not able to understand some typecasting syntaxes. For eg.
float f=7.0;
short s=*(short *)&f;
What's happening here short s=*(short *)&f? Looks like we're casting something as a pointer to a short and then initializing s to value stored in the address pointed to by something.
Now, this something looks like the address of va...
If i have a int and a size_t variable,can i compare them like:
int i=1;
size_t y=2;
if(i==y)
do something..
or i have to type-cast one of them?
...
I have a hack program; it injects some functions into a target process to control it. The program is written in C++ with inline assembly.
class GameProcMain {
// this just a class
};
GameProcMain* mainproc; // there is no problem I can do =(GameProcMain*)0xC1EA90
Now I want to define a class function (which set ecx to class pointer)...
I have two classes
public class A
{
public A()
{
}
}
public class B:A
{
public B()
{
}
}
and it the code in Main is as follows
A oa = new B();
B ob = new A();
Here line 1 compiles successfully while line 2 displays typecasting error. Why this happens. ...
I understand that the following code won't work
Float a=3
because its translated as Float a=Integer.valueOf(3). We'll have a Float reference on the LHS and an Integer object on the RHS, which is incompatible. But :
1.
`Short a=3;`
This works, though here again, we'll have a Short reference on the LHS and an Integer object on ...
I have a function uint8_t EE_Write(uint8_t addr, uint8_t len, uint8_t * buf) that takes a pointer to some data that it will write to memory, and a uint16_t myword that I want to give it. The basic
EE_Write(0,sizeof(myword),&myword);
gives me the compiler warning "Indirection to different types ('unsigned int *const ' instead of 'unsi...
Hi everybody.
Suppose I have two classed Base and Derived, i.e.:
#include <iostream>
class Base {
public:
Base ()
: m_name("Base")
{
}
virtual ~Base ()
{
}
virtual void method (std::ostream & out) const
{
out << m_name << std::endl;
...
I understand typecasting...but only in retrospect. My process to figure out what requires typecasting in expressions is usually retroactive because I can't predict when it will be required because I don't know how the compiler steps through them. A somewhat trite example:
int8_t x = -50;
uint16_t y = 50;
int32_t z = x * y;
On my 8-b...
I have a conversion like this:
Class1 *p1;
Class2 *p2 = new Class2();
p1 = (Class1 *) p2;
Can I override the typecast operator above to return a custom Class1 object pointer?
If yes how?
EDIT: My exact problem is that I have code like this:
if (*$1 == ArrayType(AnyType()))
{
$$ = ((ArrayType *) $1)->getElementsType();
}
Operat...
Consider the following two enums:
enum MyEnum1 {
Value1 = 1,
Value2 = 2,
Value3 = 3
}
enum MyEnum2 {
Value1 = 'a',
Value2 = 'b',
Value3 = 'c'
}
I can retrieve the physical value represented by these enum values through explicit casting, ((int)MyEnum1.Value2) == 2 or ((char)MyEnum2.Value2) == 'b', but what i...
I have the code below:
class A
{
};
class B: public virtual A
{
public:
B()
{
cerr << "B()";
}
B(const A& a)
{
cerr << "B(const A&)";
}
};
class C: public B
{
};
int main(int argc, char **argv)
{
B *b = new B(C());
}
To my surprise B(const A& a) isn't called. Why is that?
...
I need to convert an UIntPtr object to that of IntPtr in my C# .NET 2.0 application. How can this be accomplished? I don't suppose it's as simple as this:
UIntPtr _myUIntPtr = /* Some initializer value. */
object _myObject = (object)_myUIntPtr;
IntPtr _myIntPtr = (IntPtr)_myObject;
Thanks.
...
Please consider the following code.
enum type {CONS, ATOM, FUNC, LAMBDA};
typedef struct{
enum type type;
} object;
typedef struct {
enum type type;
object *car;
object *cdr;
} cons_object;
object *cons (object *first, object *second) {
cons_object *ptr = (cons_object *) malloc (sizeof (cons_object));
ptr->type = CONS;
...
What is the big difference between parsing and typecasting?
I try to use type casting to a string and it gives me error.
Something like this:
string str = "10";
int i = (int) str;
...
is there any way by which I can change an id type to NSString object?
note the following line of my code.
NSString *value = [appDelegate.bird_arr objectAtIndex:rowClicked] ;
in this appDelegate is object of my AppDelegate class in a navigation based program and bird_arr is object of NSMutableArray.
I want to use the string written in ...
I have a project where I have a lot of related Info classes and I was considering putting up a hierarchy by having a AbstractInfo class and then a bunch of derived classes, overriding the implementations of AbstractInfo as necessary. However it turns out that in C++ using the AbstractInfo class to then create one of the derived objects ...
I have a function:
void *findPos(void *param)
{
int origPos=(int)param;
...
}
Which I am calling as a thread runner:
pthread_create( &threadIdArray[i], NULL, findPos, (void *)i );
Now, this way, I get the value of origPos as the typecasted void pointer param, ie. i. This feels like a dirty hack to get around the limitation of...
For a fun project I wanted to make a binary clock in PHP, so basically for simplicity's sake I used date("H:m:s"); to get the time in string format, then used str_split(); to separate each string letter into an array.
My code is here to work with it:
$time = str_split($time);
//I tried $time = array_map(intval, $time); here but no dice...