Embedded Linux c How to print a 64bit Longlong integral type Int64_t__linux

Source: Internet
Author: User

64-bit unsigned integer printing mode:

#include <stdio.h>
unsigned long long ll=0x9102928374747474;
void Main ()
{
printf ("**************\n");
printf ("%x,%llx\n", ll,ll);
printf ("%llu\n", LL);
printf ("**************\n");
}

Integral type different length small common sense temperature reason:

D,lx,ld,,lu, these are all 32-bit output.
Hd,hx,hu, these are all output 16-bit data,
Hhd,hhx,hhu, these are all output 8 bits,
LLD,LL,LLU,LLX, these are all output 64 bits,

printf ("%llu",..... )
%llu is a 64-bit unsigned
%LLX is a 64-digit 16 number.


Summary of basic data types learning under Dev-c++

Environment: Dev-c++ 4.9.6.0 (GCC/MINGW32), using-wall compilation options

Basic types include byte type (char), integer (int), and floating-point type (float/double).

When you define a base type variable, you can use the Symbol property signed, unsigned (for char, int), and length properties short, long (for

in int, double) to explain the range and precision of the variables.

The following is a list of the dev-c++ and values of the base type:

Symbol attribute length attribute base type placeholder value range Input character example output example

----Char 8-2^7 ~ 2^7-1%c%c,%d,%u

Signed--char 8-2^7 ~ 2^7-1%c%c,%d,%u

unsigned--char ~ 2^8-1%c%c,%d,%u

[Signed] short [int] 16-2^15 ~ 2^15-1%HD

unsigned short [int] 0 ~ 2^16-1%hu,%ho,%HX

[Signed]--int 32-2^31 ~ 2^31-1%d

unsigned--[int] 2^32-1%u,%o,%x

[Signed] long [int] 32-2^31 ~ 2^31-1%ld

unsigned long [int] 0 ~ 2^32-1%lu,%lo,%LX

[signed] long long[int] 64-2^63 ~ 2^63-1%i64d

unsigned long long[int] 0 ~ 2^64-1%i64u,%i64o,%i64x

----Float 32+/-3.40282e+038%f,%e,%g

----Double 64+/-1.79769e+308%lf,%le,%lg%f,%e,%g

--Longdouble-1.79769E+308%LF,%le,%LG

A few notes:

1. Watch out! Each row in the table, representing a basic type. The "[]" representative can be omitted.

For example: Char, signed char, unsigned char are three distinct types;

int, short, and long are three distinct types.

You can use the function overload attribute of C + + to authenticate, such as:

void Func (char ch) {}

void Func (signed char ch) {}

void Func (unsigned char ch) {}

is three different functions.

2. char/signed char/unsigned char type data length is 1 bytes;

Char is a signed type, but is different from signed Char.

Attention! Not all compilers do this, the char data length is not necessarily 1 bytes, and char is not necessarily a signed type.

3. When converting char/signed char to int, the highest sign bit 1 is extended to cause an operational problem.

Therefore, it is appropriate to use unsigned char if there is a byte value greater than 127 in the data to be processed.

If a bit operation is involved in the program, the unsigned variable should also be used.

4. char/signed char/unsigned char output, using the format character%c (in characters);

Or use%d,%u,%x/%x,%o, output in integer mode;

When you enter, you should use%c, and if you use an integer, Dev-c++ gives a warning, which is not recommended.

5. The length of the int, is 16 bits or 32 bits, and is related to the compiler word length.

16-bit compilers (such as the compiler used by TC), int is 16 bits, 32-bit compilers (such as the compiler used by VC cl.exe), int is 32

Bit

6. Integer data can be input and output using%d (signed 10),%o (unsigned 8), or%x/%x (unsigned 16).

The format character%u, which represents unsigned, is an unsigned 10-way.

7. Integer prefix h indicates that short,l represents long.

When input and output short/unsigned short, it is not recommended to use the int's format character%d/%u and so on, prefix h.

This habit error comes from TC. The length of the int and the default symbol attributes are identical to the TC,

So the two types are treated as the same, and the input and output is done in int mode.

8. For input and output of long type:

"%lld" and "%llu" are the format characters used by Linux gcc/g++ for long int type input and output.

"%i64d" and "%i64u" are the format descriptions used in the Microsoft VC + + library for input and output __int64 types.

The compiler used by dev-c++ is Mingw32,mingw32 is one of the x86-win32 gcc subprojects, and the compiler core is GCC under Linux.

The function parameter type check is in the compile phase, the GCC compiler checks the format string, apparently it does not recognize "%i64d",

Therefore, a warning "unknown conversion type character ' I ' in format" is given. For "%lld" and "%llu", gcc

Accepted, of course.

MINGW32 uses GCC rules to check syntax during compilation and uses Microsoft libraries for connections and runtimes.

The printf and scanf functions in this library certainly do not recognize Linux gcc under "%lld" and "%llu", but for "%i64d" and "%i64u," it is

Willing to accept, and can work properly.

9. Floating-point data input can be used%f,%e/%e or%g/%g,scanf automatically processed according to the input data form.

You can use%f (normal),%e/%e (exponential), or%g/%g (automatic selection) when exporting.

10. Floating-point parameter stack rule: float (4-byte) type expands to double (8 bytes) into the stack.

So in the input, you need to distinguish between float (%f) and double (%LF), and in the output, with%f.

The printf function outputs the float (expanded double) and double data that is pressed onto the stack according to the rules of double.

If you specify the%LF format character at output time, the Gcc/mingw32 compiler will give a warning.

Dev-c++ (GCC/MINGW32) can choose whether the length of float is the same as double.

12. The prefix L denotes long (double).

Although a long double is 4 bytes longer than a double, the range of values represented is the same.

The length, precision, and representation range of a long double are related to the compiler, operating system, etc. used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.