long-long

64-bit G++ 4.6.3 doesn't treat longs as long longs in specialised function templates, even though they're the same size. Is this a bug?

不羁的心 提交于 2019-12-11 04:54:37
问题 Consider the following code: #include <iostream> #include <cinttypes> template<class T> void f(); template<> inline void f<long long>() { std::cout<<"f<long long>()"<<std::endl; } int main(int , char** ) { std::cout<<"sizeof(long)="<<sizeof(long)<<std::endl; std::cout<<"sizeof(long long)="<<sizeof(long long)<<std::endl; f<int64_t>(); return 0; } 32-bit G++ 4.6.3 compiles this successfully and produces the output: sizeof(long)=4 sizeof(long long)=8 f<long long>() Compiling under 64-bit G++ 4.6

Convert long long to string in C?

时光毁灭记忆、已成空白 提交于 2019-12-04 07:16:12
I'd like to convert a long long to a string in C. long long x = 999; I'd like to convert x to a string. How could I go about doing that? Thanks. long long x = 999; char str[256]; sprintf(str, "%lld", x); printf("%s\n", str); 来源: https://stackoverflow.com/questions/16095248/convert-long-long-to-string-in-c

Rounding issue when using long long on PIC

一个人想着一个人 提交于 2019-12-02 04:56:15
问题 I'm doing a simple bit of maths on a PIC microcontroller, running code in C and using MPLABX and the xc16 compiler. This is the code: double mydouble = 0.019440; long long int mypower = 281474976710656; long long int result = mypower*mydouble; Printing out 'result' gives me 5,471,873,794,048; while it should give 5,471,873,547,255. Any idea what is causing this problem, and how I can rectify it? Thanks 回答1: xc16 handles both double and float as 32-bit data types by default. You need to give

Why do C compilers specify long to be 32-bit and long long to be 64-bit?

此生再无相见时 提交于 2019-11-30 18:41:32
Wouldn't it have made more sense to make long 64-bit and reserve long long until 128-bit numbers become a reality? Yes, it does make sense, but Microsoft had their own reasons for defining "long" as 32-bits. As far as I know, of all the mainstream systems right now, Windows is the only OS where "long" is 32-bits. On Unix and Linux, it's 64-bit. All compilers for Windows will compile "long" to 32-bits on Windows to maintain compatibility with Microsoft. For this reason, I avoid using "int" and "long". Occasionally I'll use "int" for error codes and booleans (in C), but I never use them for any

Why do C compilers specify long to be 32-bit and long long to be 64-bit?

北城余情 提交于 2019-11-30 02:57:15
问题 Wouldn't it have made more sense to make long 64-bit and reserve long long until 128-bit numbers become a reality? 回答1: Yes, it does make sense, but Microsoft had their own reasons for defining "long" as 32-bits. As far as I know, of all the mainstream systems right now, Windows is the only OS where "long" is 32-bits. On Unix and Linux, it's 64-bit. All compilers for Windows will compile "long" to 32-bits on Windows to maintain compatibility with Microsoft. For this reason, I avoid using "int

Should I use long long or int64_t for portable code?

走远了吗. 提交于 2019-11-28 22:24:27
I have an open-source codebase that is written in both C and C++. I'm looking for an integer type that is guaranteed to be at least 64 bits wide, which can be reliably compiled on most OS X (Intel, 64-bit) and Linux boxes with open-source C and C++ compilers, without too much extra work on the end user's part. Windows and 32-bit client support are not important at this time. I did some testing on OS X, and the latest GCC that ships with the developer tools does not support C+11 mode (and therefore does not seem to guarantee availability of long long ). Clang does not support this, either,

long long vs int multiplication

喜夏-厌秋 提交于 2019-11-28 10:16:29
Given the following snippet: #include <stdio.h> typedef signed long long int64; typedef signed int int32; typedef signed char int8; int main() { printf("%i\n", sizeof(int8)); printf("%i\n", sizeof(int32)); printf("%i\n", sizeof(int64)); int8 a = 100; int8 b = 100; int32 c = a * b; printf("%i\n", c); int32 d = 1000000000; int32 e = 1000000000; int64 f = d * e; printf("%I64d\n", f); } The output with MinGW GCC 3.4.5 is (-O0): 1 4 8 10000 -1486618624 The first multiplication is casted to an int32 internally (according to the assembler output). The second multiplication is not casted. I'm not sure

How do I check if A+B exceed long long? (both A and B is long long) [duplicate]

☆樱花仙子☆ 提交于 2019-11-28 07:26:13
This question already has an answer here: How do I detect unsigned integer multiply overflow? 31 answers I have two numbers: A and B . I need to calculate A+B somewhere in my code. Both A and B are long long , and they can be positive or negative . My code runs wrong, and I suspect the problem happens when calculating A+B . I simply want to check if A+B exceed long long range. So, any method is acceptable, as I only use it for debug. Daniel Fischer Overflow is possible only when both numbers have the same sign. If both are positive, then you have overflow if mathematically A + B > LLONG_MAX ,

What kind of data type is “long long”?

末鹿安然 提交于 2019-11-28 07:19:05
I don't know this type. Is that the biggest one from all? I think it is an integer type, right? Or is it a floating point thing? Bigger than double? According to C99 standard, long long is an integer type which is at least 64-bit wide. There are two integer 64-bit types specified: long long int and unsigned long long int So, yes, this is the biggest integer type specified by C language standard (C99 version). There is also long double type specified by C99. It's an extended precision floating point numeric data type long for 80-bits on most popular x86-based platforms and implementations of C

sprintf for unsigned _int64

醉酒当歌 提交于 2019-11-27 09:13:39
I am having following code. output of second %d in sprintf is always shown as zero. I think i am specifying wrong specifiers. Can any one help me in getting write string with right values. And this has to achieved in posix standard. Thanks for inputs void main() { unsigned _int64 dbFileSize = 99; unsigned _int64 fileSize = 100; char buf[128]; memset(buf, 0x00, 128); sprintf(buf, "\nOD DB File Size = %d bytes \t XML file size = %d bytes", fileSize, dbFileSize); printf("The string is %s ", buf); } Output: The string is OD DB File Size = 100 bytes XML file size = 0 bytes DevSolar I don't know