473,387 Members | 1,440 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,387 software developers and data experts.

int vs long


The readFile function from the win32 package aparently really expect an
integer :

def inWaiting(self):
"""Returns the number of bytes waiting to be read"""
flags, comstat = ClearCommError(self.__handle)
return comstat.cbInQue

ReadFile(h, s.inWaiting())

My code crashes because inWaiting returns a long, not an int

Why is that different on my machine and my collegues ? Have I or he
installed a wrong version of a package?
CPython 2.5.

Was not expecting int<->long type problems in excactly python language.
Is that because we are navigating so close to the win32 api that the types
are more strictly enforced ?

Thx in advance
Troels


Dec 16 '07 #1
5 3421
En Sun, 16 Dec 2007 20:28:02 -0300, Troels Thomsen <"nej
tak..."@bag.python.orgescribi�:
>
The readFile function from the win32 package aparently really expect an
integer :

def inWaiting(self):
"""Returns the number of bytes waiting to be read"""
flags, comstat = ClearCommError(self.__handle)
return comstat.cbInQue

ReadFile(h, s.inWaiting())

My code crashes because inWaiting returns a long, not an int
That's very strange. The cbInQue field is a DWORD in C, seen as an int in
Python. How do you know it returns a long?
Why is that different on my machine and my collegues ? Have I or he
installed a wrong version of a package?
CPython 2.5.
And pywin32 build 210, I presume.
Was not expecting int<->long type problems in excactly python language.
Is that because we are navigating so close to the win32 api that the
types
are more strictly enforced ?
Somewhat. At the API level, function arguments have to be converted to
native C types, like ReadFile expecting a DWORD. Any number greater than
2**32 won't fit, but I can't think how such thing could happen looking at
those few posted code lines.

--
Gabriel Genellina

Dec 17 '07 #2
Gabriel Genellina <ga*******@yahoo.com.arwrote:
En Sun, 16 Dec 2007 20:28:02 -0300, Troels Thomsen <"nej
tak..."@bag.python.orgescribi?:

The readFile function from the win32 package aparently really expect an
integer :

def inWaiting(self):
"""Returns the number of bytes waiting to be read"""
flags, comstat = ClearCommError(self.__handle)
return comstat.cbInQue

ReadFile(h, s.inWaiting())

My code crashes because inWaiting returns a long, not an int

That's very strange. The cbInQue field is a DWORD in C, seen as an int in
Python. How do you know it returns a long?
Why is that different on my machine and my collegues ? Have I or he
installed a wrong version of a package?
CPython 2.5.

And pywin32 build 210, I presume.
Was not expecting int<->long type problems in excactly python language.
Is that because we are navigating so close to the win32 api that the
types
are more strictly enforced ?

Somewhat. At the API level, function arguments have to be converted to
native C types, like ReadFile expecting a DWORD. Any number greater than
2**32 won't fit, but I can't think how such thing could happen looking at
those few posted code lines.
Actually any number >= 2**31 won't fit in a python int.
>>2**31
2147483648L

According to my headers DWORD is defined like this

typedef unsigned long DWORD;

So you might see longs returned when you expected ints if the result
was >= 0x8000000.

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Dec 17 '07 #3
En Mon, 17 Dec 2007 10:30:05 -0300, Nick Craig-Wood <ni**@craig-wood.com>
escribió:
Gabriel Genellina <ga*******@yahoo.com.arwrote:
> En Sun, 16 Dec 2007 20:28:02 -0300, Troels Thomsen <"nej
tak..."@bag.python.orgescribi?:
>
The readFile function from the win32 package aparently really expect
an
integer :

def inWaiting(self):
"""Returns the number of bytes waiting to be read"""
flags, comstat = ClearCommError(self.__handle)
return comstat.cbInQue

ReadFile(h, s.inWaiting())

My code crashes because inWaiting returns a long, not an int

That's very strange. The cbInQue field is a DWORD in C, seen as an int
in
Python. How do you know it returns a long?
Why is that different on my machine and my collegues ? Have I or he
installed a wrong version of a package?
CPython 2.5.

And pywin32 build 210, I presume.
Was not expecting int<->long type problems in excactly python
language.
Is that because we are navigating so close to the win32 api that the
types
are more strictly enforced ?

Somewhat. At the API level, function arguments have to be converted to
native C types, like ReadFile expecting a DWORD. Any number greater
than
2**32 won't fit, but I can't think how such thing could happen looking
at
those few posted code lines.

Actually any number >= 2**31 won't fit in a python int.
>>2**31
2147483648L

According to my headers DWORD is defined like this

typedef unsigned long DWORD;

So you might see longs returned when you expected ints if the result
was >= 0x8000000.
More than 2GB waiting to be read from a serial port? If that were the case
the OP has a very big throughput problem rather than an API mismatch :)

--
Gabriel Genellina

Dec 18 '07 #4
"Nick Craig-Wood" <nic...od.comwrote:
So you might see longs returned when you expected ints if the result
was >= 0x8000000.
did you mean 0x80000000 ?

;-)

- Hendrik

Dec 18 '07 #5
Hendrik van Rooyen <ma**@microcorp.co.zawrote:
"Nick Craig-Wood" <nic...od.comwrote:
So you might see longs returned when you expected ints if the result
was >= 0x8000000.

did you mean 0x80000000 ?

;-)
Yes - well spotted!
--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Dec 20 '07 #6

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

Similar topics

8
by: Tim Clacy | last post by:
How is a 64 bit type defined in strict C++? It seems C has support for 'long long' since C99, but not so for C++? Looking through one compiler vendor's standard library headers has clouded the...
7
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For...
5
by: Mark Shelor | last post by:
Problem: find a portable way to determine whether a compiler supports the "long long" type of C99. I thought I had this one solved with the following code: #include <limits.h> #ifdef...
29
by: Richard A. Huebner | last post by:
Is the unsigned long long primitive data type supported in ANSI standard C? I've tried using it a couple of times in standard C, but to no avail. I'm using both MS VIsual C++ 6, as well as the...
9
by: luke | last post by:
Hi everybody, please, can someone explain me this behaviour. I have the following piece of code: long long ll; unsigned int i = 2; ll = -1 * i; printf("%lld\n", ll);
21
by: Charles Sullivan | last post by:
I maintain/enhance some inherited FOSS software in C which has compiler options for quite a few different Unix-like operating systems, many of which I've never even heard of. It would be...
12
by: Ahmad Jalil Qarshi | last post by:
Hi, I have an integer value which is very long like 9987967441778573855. Now I want to convert it into equivalent Hex value. The result must be 8A9C63784361021F I have used...
2
by: PengYu.UT | last post by:
Hi, In python, triple quote (""") can be used to quote a paragraph (multiple lines). I'm wondering if there is any equivalent in C++. For the following code, I could write the long string in a...
10
by: ratcharit | last post by:
Currently using cosine function in math.h Currently I get: 1 = cos(1e^-7) Is there another way for cos to return value of high accuracy say: 0.999999 = cos(1e^-7)
15
by: Oliver Graeser | last post by:
I need a >49 bit integer type. tried sizeof(long long), says 8. 8 byte = 64 bit right? but when I try to assign a value with more than 32 bit, it fails. To illustrate: for (i=0; i<64; i++){...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.