i use python ctypes module to cal crc from c++ function it return uint64_t type. In python, i do not set restype(c_long_long), i get a python int value -870013293 , however set restype the value is 14705237936323208851. can you tell me the relation about int_val and long_val.
python ctypes module how to transfer uint64_t from c++func return to python int,not set restype=c_long_long
711 Views Asked by nemo AtThere are 2 best solutions below
Сергей Кох
On
Here is what is written in the documentation: https://docs.python.org/3/library/ctypes.html#module-ctypes
Python integers are passed as the platforms default C int type, their value is masked to fit into the C type.
Therefore, default the value is treated as c_int, and:
Represents the C signed int datatype. The constructor accepts an optional integer initializer; no overflow checking is done. On platforms where sizeof(int) == sizeof(long) it is an alias to c_long.
Since there is no overflow and the number is signed, instead of a large number, it can output any number from -2,147,483,648 to 2,147,483,647.(32 bits)
If you know the return value will be unsigned and explicitly type c_uint64 ( usually an alias for c_ulonglong), then you'll get the value you want.(64 bits)
Related Questions in PYTHON
- new thread blocks main thread
- Extracting viewCount & SubscriberCount from YouTube API V3 for a given channel, where channelID does not equal userID
- Display images on Django Template Site
- Difference between list() and dict() with generators
- How can I serialize a numpy array while preserving matrix dimensions?
- Protractor did not run properly when using browser.wait, msg: "Wait timed out after XXXms"
- Why is my program adding int as string (4+7 = 47)?
- store numpy array in mysql
- how to omit the less frequent words from a dictionary in python?
- Update a text file with ( new words+ \n ) after the words is appended into a list
- python how to write list of lists to file
- Removing URL features from tokens in NLTK
- Optimizing for Social Leaderboards
- Python : Get size of string in bytes
- What is the code of the sorted function?
Related Questions in C++
- C++ using std::vector across boundaries
- Linked list without struct
- Connecting Signal QML to C++ (Qt5)
- how to get the reference of struct soap inherited in C++ Proxy/Service class
- Why we can't assign value to pointer
- Conversion of objects in c++
- shared_ptr: "is not a type" error
- C++ template using pointer and non pointer arguments in a QVector
- C++ SFML 2.2 vectors
- Lifetime of temporary objects
- I want to be able to use 4 different variables in a select statement in c ++
- segmentation fault: 11, extracting data in vector
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- How can I print all the values in this linked list inside a hash table?
- Configured TTL for A record(s) backing CNAME records
Related Questions in INTEGER
- String replace with integer not working
- How can I parse fixed-length, non-delimited integers with attoparsec?
- 0 randomly becomes 55?
- Why did Java 8 introduce *Integer.sum(int a, int b)*
- How do char and int work in C++
- Separating an Integer
- How do you generate specific random number?
- Regular expression that would allow numbers from 1-9 excluding 0 and alphabets
- How can I send a integer from my Java file to my XML folder? (Android Studio)
- C++ unsigned long doesn't wrap around after 4294967295
- Java format integer limiting width by truncating to the right
- Transform price with currency to single number if no numbers after comma
- how to stop the program if the value i get for amount_notes is not an integer?
- Get the big-endian byte sequence of integer in Python
- Mapping int to int (in Java)
Related Questions in CTYPES
- how use ctypes with msvc*.dll from within matlab on windows
- how install shapely on windows so it can be imported from matlab?
- ctypes non-valid Win32 dll with valid win32 dll
- Python 3.4 ctypes wrap for a mingw-w64 compiled C-based dll
- Setting _fields_ dynamically in ctypes.Structure
- Using Rust returned array in Python using ctypes
- Converting .so file of linux to a .dll file of windows
- How to pass a C structure in Python
- how to cast LP_LP_c_longlong instance from pointer to LP_c_longlong
- what are the differences among the ways to access msvcrt in python on windows?
- Calling C function from Python - undefined symbol error
- Python CDLL load library with different dependency QT version
- Convert Rust vector of tuples to a C compatible structure
- ctypes error AttributeError symbol not found, OS X 10.7.5
- How to write my following C code using setjmp/longjmp in Python?
Related Questions in UINT64
- Convert uint64 to int64 without loss of information
- Best way to convert uint64_t to jlong
- C /C++ long long to Java long
- sprintf for unsigned _int64
- Increase Hex2dec or dec2hex output range in Matlab
- Converting input variable to Uint64
- Why minus operator on uint64_t gives me wrong results?
- Printing uint64_t* value in C
- Are there platforms that do not support uint64_t?
- Runtime error, makes my .exe crash and I am not sure why
- How to multiply integers larger than uint64?
- Why does PRIx64 print "lx" instead of 16 hex chars?
- Where to properly get _LONGLONG_TYPE defined
- Cannot declare any signed Integer types in C#
- Bitshifting a uint64_t gives wrong result
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The default return type for
ctypesisc_intwhich is a 32-bit signed value. If you don't set.restype = c_uint64for a 64-bit value, the return value is converted incorrectly from C to Python. You can see that the value was truncated to 32 bits if you display it in hexadecimal:Note that the last 32 bits of the 64-bit value match the 32-bit signed value.