Solved

char() vs (char)

Posted on 2004-10-06
6
540 Views
Last Modified: 2010-04-24
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
0
Comment
Question by:alanpong
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:nonubik
ID: 12236750
'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)
0
 
LVL 1

Author Comment

by:alanpong
ID: 12237232
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
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12237379
>is char(dw) equalivent to (char) dw?

>char a = char(dw);
it's like you call the constructor of a class with a value
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 1

Author Comment

by:alanpong
ID: 12237423
>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)?

0
 
LVL 16

Accepted Solution

by:
nonubik earned 50 total points
ID: 12237587
>(char)dw should be faster than char(dw)?
it's the same

>can i found its definition in .h file?
'char' is a fundamental data type. It does not have a definition in an external file. (i.e. .h)
0
 
LVL 1

Author Comment

by:alanpong
ID: 12237732
>>(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'
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question