Solved

char() vs (char)

Posted on 2004-10-06
6
538 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I write a C++ program (coursework) 20 124
Get the height value of a parent form 2 178
What is the real difference between C++ and Visual C++.NET? 7 115
Setup project 6 72
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 censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

778 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