473,378 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Promotion converts long int to int implicitly ?

Hello

I have an overloaded function like this:

BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, long);
BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, int);

And then I call the function like this:
SetFieldValue(pRecordset, _T("Order"), long(i)+1);
and the debugger shows that the int overload of my fuction is called.

Is long( i ) + 1 not of type long ? Why is the int overload selected ?

Thank you
Timothy Madden
Romania
-----------------------------------------
And I don't wanna miss a thing
Jul 22 '05 #1
4 1184
Timothy Madden wrote:
Hello

I have an overloaded function like this:

BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, long);
BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, int);

And then I call the function like this:
SetFieldValue(pRecordset, _T("Order"), long(i)+1);
and the debugger shows that the int overload of my fuction is called.

Is long( i ) + 1 not of type long ? Why is the int overload selected ?


This seems contrary to the standard, which says in section 5, point 9,
item 7: "Otherwise, if either operand is long, the other shall be
converted to long."

Jacques.
Jul 22 '05 #2
Jacques Labuschagne wrote:
Timothy Madden wrote:
Hello

I have an overloaded function like this:

BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, long);
BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, int);

And then I call the function like this:
SetFieldValue(pRecordset, _T("Order"), long(i)+1);
and the debugger shows that the int overload of my fuction is called.

Is long( i ) + 1 not of type long ? Why is the int overload selected ?

This seems contrary to the standard, which says in section 5, point 9,
item 7: "Otherwise, if either operand is long, the other shall be
converted to long."


It is contrary to the Standard, but it is also a bug in VC++ v 6. It
was apparently fixed in v 7[.1]

V
Jul 22 '05 #3
"Timothy Madden" <ba****@rmv.spam.home.ro> wrote:
Hello

I have an overloaded function like this:

BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, long);
BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, int);

And then I call the function like this:
SetFieldValue(pRecordset, _T("Order"), long(i)+1);
and the debugger shows that the int overload of my fuction is called.


Possibly your compiler has optimised away the 'long' overload,
try turning off all optimisation and then tracking it again.
Jul 22 '05 #4

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:RR****************@newsread1.dllstx09.us.to.v erio.net...
Jacques Labuschagne wrote:
Timothy Madden wrote:
Hello

I have an overloaded function like this:

BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, long);
BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, int);

And then I call the function like this:
SetFieldValue(pRecordset, _T("Order"), long(i)+1);
and the debugger shows that the int overload of my fuction is called.

Is long( i ) + 1 not of type long ? Why is the int overload selected ?

This seems contrary to the standard, which says in section 5, point 9,
item 7: "Otherwise, if either operand is long, the other shall be
converted to long."


It is contrary to the Standard, but it is also a bug in VC++ v 6. It
was apparently fixed in v 7[.1]

Oh, thank you very much !!
I'm happy someone else knows about this problem.

Can you tell me exactly what the bug is and where can I find a list with VC
6 bugs if it exists ?
I did encounter other problems like this in my app

Thank you
Timothy Madden
Romania
-------------------------------------------------------------
And I don't wanna miss a thing
Jul 22 '05 #5

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

Similar topics

8
by: BigMan | last post by:
Can someone cite the rules for type promotion in C++? And, in particular, what is the type of the result of adding 2 values of type char?
9
by: Fred Ma | last post by:
Hello, I've been trying to clear up a confusion about integer promotions during expression evaluation. I've checked the C FAQ and C++ FAQ (they are different languages, but I was hoping one...
20
by: Russell Shaw | last post by:
Hi, I'm using gcc-3.4.3 on a linux pc. The ints and long ints are 32 bits and long long ints are 64 bits. When i have: int num=9600; long long int reg=(long long)800000000000/(5000000*num);...
112
by: Carsten Hansen | last post by:
Suppose I'm using an implementation where an int is 16 bits. In the program below, what function is called in the first case, and what is called in the second case? Also, if there is a difference...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
3
by: shmartonak | last post by:
I have the following program. Under linux I've compiled it with gcc and in DOS I've compiled it with TURBOC 2.01. I get different outputs when I run it. /* start of program */ #include...
10
by: Christian Kandeler | last post by:
Hi, consider the following program: #include <stdio.h> int main(void) { struct test { unsigned int x : 1;
4
by: gen_tricomi | last post by:
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal...
6
by: sarathy | last post by:
Hi, What is integer promotion? How is it different from arithmetic conversion? Regards, Sarathy
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.