Solved

char() vs (char)

Posted on 2004-10-06
6
535 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft Visual C++ Runtime Lirary Runtime Error 15 336
How to correct a C6001issue? 5 207
.Net Errors Service Crashing 5 111
SHA256 Code Signing 4 148
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…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now