vehomzzz
vehomzzz

Reputation: 44568

How does function-style cast syntax work?

I guess I am a bit puzzled by the syntax. What does the following mean?

typedef char *PChar;
hopeItWorks = PChar( 0x00ff0000 );

Upvotes: 3

Views: 3336

Answers (3)

Alexey Malistov
Alexey Malistov

Reputation: 26975

SomeType(args) means explicit constructor call if SomeType is user-defined type and usual c-cast (SomeType)args if SomeType is fundamental type or a pointer.

PChar is equivalent to char * (pointer). Thus hopeItWorks = (char *)0x00ff0000;

Upvotes: 5

aJ.
aJ.

Reputation: 35450

typedef char *PChar;

Its typedef of char* to Pchar. Instead of using char* you can define variables with Pchar.

hopeItWorks = PChar( 0x00ff0000 );

Its equivalent to ==>

 hopeItWorks = (char *)( 0x00ff0000 );

Upvotes: 4

John Kugelman
John Kugelman

Reputation: 361565

It is equivalent to (PChar) 0x00ff0000 or (char *) 0x00ff0000. Syntactically think of it as invoking a one-argument constructor.

Upvotes: 5

Related Questions