Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

char() vs (char)

Posted on 2004-10-06
6
Medium Priority
?
546 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
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 
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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

824 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