Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does function-style cast syntax work?

Tags:

c++

casting

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

typedef char *PChar;
hopeItWorks = PChar( 0x00ff0000 );
like image 323
vehomzzz Avatar asked May 11 '26 14:05

vehomzzz


2 Answers

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

like image 136
John Kugelman Avatar answered May 14 '26 04:05

John Kugelman


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;

like image 31
Alexey Malistov Avatar answered May 14 '26 02:05

Alexey Malistov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!