Link to home
Start Free TrialLog in
Avatar of alanpong
alanpong

asked on

char() vs (char)

win2k, vc++6.0

What is the different between :
DWORD dw;
char a = char(dw);
char b = (char)dw;

Is char() a marco or a function?
which *.h file can i found its definition?
Thank you very much.
Rgds.
Alan
--END
Avatar of nonubik
nonubik

'char' is a type

The char type is used to store the integer value of a member of the representable character set. That integer value is the ASCII code corresponding to the specified character.

>char b = (char)dw;
here you used the cast operator (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/vcrefCastOperator.asp)
Avatar of alanpong

ASKER

i know (char)dw is a casting.

how about this?
char a = char(dw);

is char( X ) a marco or function?
or standard c++ usage?

is char(dw) equalivent to (char) dw?

--END
>is char(dw) equalivent to (char) dw?

>char a = char(dw);
it's like you call the constructor of a class with a value
>it's like you call the constructor of a class with a value
can i found its definition in .h file?

(char)dw should be faster than char(dw)?

ASKER CERTIFIED SOLUTION
Avatar of nonubik
nonubik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>(char)dw should be faster than char(dw)?
>it's the same

struct s
{
  int z;
} s;

char c = (char) s;
char d = char(s);

yes, proved, the compiler tell me both assignments above is trying to do type casting.
error C2440: 'type cast' : cannot convert from 'struct s' to 'char'
error C2440: 'type cast' : cannot convert from 'struct s' to 'char'