473,461 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Difference between (long) x and long(x)?

I have never fully understood what the difference is between these two forms
of casting. Can anyone please clarify? long is a primitive data type so no,
it's not calling a class constructor. This is not simply a .NET feature
either, also works in VS6.
Nov 17 '05 #1
4 1182
mosimu wrote:
I have never fully understood what the difference is between these two forms
of casting. Can anyone please clarify? long is a primitive data type so no,
it's not calling a class constructor. This is not simply a .NET feature
either, also works in VS6.


Besides syntax, there is no difference. There's no difference when ctors are
involved, either. Of course, you can't do things like (char*) x using the
functional notation, and you can't creating temporaries using T() or T(x,y)
with the cast notation. But for single argument ctors, the functional and
cast notations are equivalent.

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #2
For primitive types like long it doesn't matter. But if you had a class
foo then:

(foo) x calls x's conversion function.
foo (x) calls foo's contructor.

Ramsey

Nov 17 '05 #3
Ramsey wrote:
For primitive types like long it doesn't matter. But if you had a class
foo then:

(foo) x calls x's conversion function.
foo (x) calls foo's contructor.


Nope. It's spelled out as I described in the C++ Standard, 5.2.3. The two
expressions you gave mean the same thing. Either can call a foo ctor or an x
conversion function. Here's an example:

struct X
{
operator int();
};

struct Y
{
Y(const X&);
};

void f(X x)
{
int i1 = (int) x;
int i2 = int(x);

Y y1 = (Y) x;
Y y2 = Y(x);
}
--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #4
Thank you.

"mosimu" wrote:
I have never fully understood what the difference is between these two forms
of casting. Can anyone please clarify? long is a primitive data type so no,
it's not calling a class constructor. This is not simply a .NET feature
either, also works in VS6.

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jyoti | last post by:
Hi there, I am trying to compare two strings and get the differenc in vbscript. Example: Str1="This is a test text" Str2="This is a fine test text but a little long" I like to compare str1...
17
by: Nathan Given | last post by:
Hello All, I am trying to debug a broken query. The query uses Left$(,4) instead of Left(,4). What is the difference between the Left() and Left$() functions in Microsoft Access? Thanks!...
21
by: Mac | last post by:
$ cat junk27.c #include <stdio.h> #include <string.h> int main (void) { printf("The difference between memcpy and memmove is %ld\n", (long int) memcpy - (long int) memmove); return 0; }
10
by: tinesan | last post by:
Hello fellow C programmers, I'm just learning to program with C, and I'm wondering what the difference between signed and unsigned char is. To me there seems to be no difference, and the...
3
by: Jon B | last post by:
Hi There! What is the difference between Signed and UnSigned variables in .NET Framework?? My background is just in VB6 and I have no idea what is the difference between ULong and Long etc. ...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
12
by: Veeru | last post by:
Hi, Can anyone tell me the difference between heap memory and stack stack both physically and fundamentally. It would be a real favour. Regards, Veeru
6
by: JonathanOrlev | last post by:
Hello everyone, I have a newbe question: In Access (2003) VBA, what is the difference between a Module and a Class Module in the VBA development environment? If I remember correctly, new...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.