当前位置: 首页 > news >正文

UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, FLOAT, DOUBLE

UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64

固定长度的整型,包括有符号整型或无符号整型。

整型范围¶

  • Int8 - [-128 : 127]
  • Int16 - [-32768 : 32767]
  • Int32 - [-2147483648 : 2147483647]
  • Int64 - [-9223372036854775808 : 9223372036854775807]

无符号整型范围¶

  • UInt8 - [0 : 255]
  • UInt16 - [0 : 65535]
  • UInt32 - [0 : 4294967295]
  • UInt64 - [0 : 18446744073709551615]

FLOAT/DOUBLE

一般来说,float是32位,double是64位,其极限值在C++标准库文件<float.h>中有定义,摘录下来其中一段如下,

#define DBL_EPSILON      2.2204460492503131e-016 // smallest such that 1.0+DBL_EPSILON != 1.0
#define DBL_MAX          1.7976931348623158e+308 // max value
#define DBL_MAX_10_EXP   308                     // max decimal exponent
#define DBL_MAX_EXP      1024                    // max binary exponent
#define DBL_MIN          2.2250738585072014e-308 // min positive value
#define DBL_MIN_10_EXP   (-307)                  // min decimal exponent
#define DBL_MIN_EXP      (-1021)                 // min binary exponent
#define DBL_TRUE_MIN     4.9406564584124654e-324 // min positive value

#define FLT_EPSILON      1.192092896e-07F        // smallest such that 1.0+FLT_EPSILON != 1.0
#define FLT_MAX          3.402823466e+38F        // max value
#define FLT_MAX_10_EXP   38                      // max decimal exponent
#define FLT_MAX_EXP      128                     // max binary exponent
#define FLT_MIN          1.175494351e-38F        // min normalized positive value
#define FLT_MIN_10_EXP   (-37)                   // min decimal exponent
#define FLT_MIN_EXP      (-125)                  // min binary exponent
#define FLT_TRUE_MIN     1.401298464e-45F        // min positive value

 

微软的说明与对应的char, short, int, long long

Microsoft C/C++ features support for sized integer types. You can declare 8-, 16-, 32-, or 64-bit integer variables by using the __intn type specifier, where n is 8, 16, 32, or 64.

The following example declares one variable for each of these types of sized integers:

C++Copy

__int8 nSmall;      // Declares 8-bit integer
__int16 nMedium;    // Declares 16-bit integer
__int32 nLarge;     // Declares 32-bit integer
__int64 nHuge;      // Declares 64-bit integer

The types __int8__int16, and __int32 are synonyms for the ANSI types that have the same size, and are useful for writing portable code that behaves identically across multiple platforms. The __int8 data type is synonymous with type char__int16 is synonymous with type short, and __int32 is synonymous with type int. The __int64 type is synonymous with type long long.

For compatibility with previous versions, _int8_int16_int32, and _int64 are synonyms for __int8__int16__int32, and __int64 unless compiler option /Za (Disable language extensions) is specified.

 

printf格式化输出¶

比如UINT64,

#include <stdio.h>
#include <stdint.h>
int64_t my_int = 999999999999999999;
printf("This is my_int: %I64d\n", my_int);

 

微软对格式化输出的解释:

原文地址:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=vs-2019

Format specification syntax: printf and wprintf functions

The various printf and wprintf functions take a format string and optional arguments and produce a formatted sequence of characters for output. The format string contains zero or more directives, which are either literal characters for output or encoded conversion specifications that describe how to format an argument in the output. This article describes the syntax used to encode conversion specifications in the format string. For a listing of these functions, see Stream I/O.

A conversion specification consists of optional and required fields in this form:

%[flags][width][.precision][size]type

Each field of the conversion specification is a character or a number that signifies a particular format option or conversion specifier. The required type field specifies the kind of conversion to be applied to an argument. The optional flagswidth, and precision fields control additional format aspects such as leading spaces or zeroes, justification, and displayed precision. The size field specifies the size of the argument consumed and converted.

A basic conversion specification contains only the percent sign and a type character. For example, %s specifies a string conversion. To print a percent-sign character, use %%. If a percent sign is followed by a character that has no meaning as a format field, the invalid parameter handler is invoked. For more information, see Parameter Validation.

 Important

For security and stability, ensure that conversion specification strings are not user-defined. For example, consider a program that prompts the user to enter a name and stores the input in a string variable that's named user_name. To print user_name, do not do this:

printf( user_name ); /* Danger! If user_name contains "%s", program will crash */

Instead, do this:

printf( "%s", user_name );

 Note

In Visual Studio 2015 The printf and scanf family of functions were declared as inline and moved to the <stdio.h> and <conio.h> headers. If you are migrating older code you might see LNK2019 in connection with these functions. For more information, see Visual C++ change history 2003 - 2015.

Type conversion specifier

The type conversion specifier character specifies whether to interpret the corresponding argument as a character, a string, a pointer, an integer, or a floating-point number. The type character is the only required conversion specification field, and it appears after any optional fields.

The arguments that follow the format string are interpreted according to the corresponding type character and the optional size prefix. Conversions for character types char and wchar_t are specified by using c or C, and single-byte and multi-byte or wide character strings are specified by using s or S, depending on which formatting function is being used. Character and string arguments that are specified by using c and s are interpreted as char and char* by printf family functions, or as wchar_t and wchar_t* by wprintf family functions. Character and string arguments that are specified by using C and S are interpreted as wchar_t and wchar_t* by printf family functions, or as char and char* by wprintf family functions. This behavior is Microsoft-specific.

Integer types such as shortintlonglong long, and their unsigned variants, are specified by using dioux, and X. Floating-point types such as floatdouble, and long double, are specified by using aAeEfFg, and G. By default, unless they are modified by a size prefix, integer arguments are coerced to int type, and floating-point arguments are coerced to double. On 64-bit systems, an int is a 32-bit value; therefore, 64-bit integers will be truncated when they are formatted for output unless a size prefix of ll or I64 is used. Pointer types that are specified by p use the default pointer size for the platform.

 Note

Microsoft-specific: The Z type character, and the behavior of the cCs, and S type characters when they are used with the printf and wprintf functions, are Microsoft extensions. The ISO C standard uses c and s consistently for narrow characters and strings, and C and S for wide characters and strings, in all formatting functions.

Type field characters

Type characterArgumentOutput format
cCharacterWhen used with printf functions, specifies a single-byte character; when used with wprintf functions, specifies a wide character.
CCharacterWhen used with printf functions, specifies a wide character; when used with wprintf functions, specifies a single-byte character.
dIntegerSigned decimal integer.
iIntegerSigned decimal integer.
oIntegerUnsigned octal integer.
uIntegerUnsigned decimal integer.
xIntegerUnsigned hexadecimal integer; uses "abcdef."
XIntegerUnsigned hexadecimal integer; uses "ABCDEF."
eFloating-pointSigned value that has the form [-]d.dddddd[d], where d is one decimal digit, dddd is one or more decimal digits depending on the specified precision, or six by default, and dd[d] is two or three decimal digits depending on the output format and size of the exponent.
EFloating-pointIdentical to the e format except that E rather than e introduces the exponent.
fFloating-pointSigned value that has the form [-]dddd.dddd, where dddd is one or more decimal digits. The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision, or six by default.
FFloating-pointIdentical to the f format except that infinity and nan output is capitalized.
gFloating-pointSigned values are displayed in f or e format, whichever is more compact for the given value and precision. The e format is used only when the exponent of the value is less than -4 or greater than or equal to the precision argument. Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it.
GFloating-pointIdentical to the g format, except that E, rather than e, introduces the exponent (where appropriate).
aFloating-pointSigned hexadecimal double-precision floating-point value that has the form [-]0xh.hhhhdd, where h.hhhh are the hex digits (using lower case letters) of the mantissa, and dd are one or more digits for the exponent. The precision specifies the number of digits after the point.
AFloating-pointSigned hexadecimal double-precision floating-point value that has the form [-]0Xh.hhhhdd, where h.hhhh are the hex digits (using capital letters) of the mantissa, and dd are one or more digits for the exponent. The precision specifies the number of digits after the point.
nPointer to integerNumber of characters that are successfully written so far to the stream or buffer. This value is stored in the integer whose address is given as the argument. The size of the integer pointed at can be controlled by an argument size specification prefix. The n specifier is disabled by default; for information see the important security note.
pPointer typeDisplays the argument as an address in hexadecimal digits.
sStringWhen used with printf functions, specifies a single-byte or multi-byte character string; when used with wprintf functions, specifies a wide-character string. Characters are displayed up to the first null character or until the precision value is reached.
SStringWhen used with printf functions, specifies a wide-character string; when used with wprintf functions, specifies a single-byte or multi-byte character string. Characters are displayed up to the first null character or until the precision value is reached.
ZANSI_STRING or UNICODE_STRING structureWhen the address of an ANSI_STRING or UNICODE_STRING structure is passed as the argument, displays the string contained in the buffer pointed to by the Buffer field of the structure. Use a size modifier prefix of w to specify a UNICODE_STRING argument—for example, %wZ. The Length field of the structure must be set to the length, in bytes, of the string. The MaximumLength field of the structure must be set to the length, in bytes, of the buffer.

Typically, the Z type character is used only in driver debugging functions that use a conversion specification, such as dbgPrint and kdPrint.

Starting in Visual Studio 2015, if the argument that corresponds to a floating-point conversion specifier (aAeEfFgG) is infinite, indefinite, or NaN, the formatted output conforms to the C99 standard. This table lists the formatted output:

ValueOutput
infinityinf
Quiet NaNnan
Signaling NaNnan(snan)
Indefinite NaNnan(ind)

Any of these values may be prefixed by a sign. If a floating-point type conversion specifier character is a capital letter, then the output is also formatted in capital letters. For example, if the format specifier is %F instead of %f, an infinity is formatted as INF instead of inf. The scanf functions can also parse these strings, so these values can make a round trip through printf and scanf functions.

Before Visual Studio 2015, the CRT used a different, non-standard format for output of infinite, indefinite, and NaN values:

ValueOutput
+ infinity1.#INF random-digits
- infinity-1.#INF random-digits
Indefinite (same as quiet NaN)digit .#IND random-digits
NaNdigit .#NAN random-digits

Any of these may have been prefixed by a sign, and may have been formatted slightly differently depending on field width and precision, sometimes with unusual effects. For example, printf("%.2f\n", INFINITY) would print 1.#J because the #INF would be "rounded" to 2 digits of precision.

 Note

If the argument that corresponds to %s or %S, or the Buffer field of the argument that corresponds to %Z, is a null pointer, "(null)" is displayed.

 Note

In all exponential formats, the minimum number of digits of exponent to display is two, using three only if necessary. By using the _set_output_format function, you can set the number of digits displayed to three for backward compatibility with code written for Visual Studio 2013 and before.

 Important

Because the %n format is inherently insecure, it is disabled by default. If %n is encountered in a format string, the invalid parameter handler is invoked, as described in Parameter Validation. To enable %n support, see _set_printf_count_output.

Flag directives

The first optional field in a conversion specification contains flag directives, zero or more flag characters that specify output justification and control output of signs, blanks, leading zeros, decimal points, and octal and hexadecimal prefixes. More than one flag directive may appear in a conversion specification, and the flag characters can appear in any order.

Flag characters

FlagMeaningDefault
-Left align the result within the given field width.Right align.
+Use a sign (+ or -) to prefix the output value if it is of a signed type.Sign appears only for negative signed values (-).
0If width is prefixed by 0, leading zeros are added until the minimum width is reached. If both 0 and - appear, the 0 is ignored. If 0 is specified for an integer format (iuxXod) and a precision specification is also present—for example, %04.d—the 0 is ignored. If 0 is specified for the a or A floating-point format, leading zeros are prepended to the mantissa, after the 0x or 0X prefix.No padding.
blank (' ')Use a blank to prefix the output value if it is signed and positive. The blank is ignored if both the blank and + flags appear.No blank appears.
#When it's used with the ox, or X format, the # flag uses 0, 0x, or 0X, respectively, to prefix any nonzero output value.No blank appears.
 When it's used with the eEfFa, or A format, the # flag forces the output value to contain a decimal point.Decimal point appears only if digits follow it.
 When it's used with the g or G format, the # flag forces the output value to contain a decimal point and prevents the truncation of trailing zeros.

Ignored when used with cdiu, or s.
Decimal point appears only if digits follow it. Trailing zeros are truncated.

Width specification

In a conversion specification, the optional width specification field appears after any flags characters. The width argument is a non-negative decimal integer that controls the minimum number of characters that are output. If the number of characters in the output value is less than the specified width, blanks are added to the left or the right of the values—depending on whether the left-alignment flag (-) is specified—until the minimum width is reached. If width is prefixed by 0, leading zeros are added to integer or floating-point conversions until the minimum width is reached, except when conversion is to an infinity or NaN.

The width specification never causes a value to be truncated. If the number of characters in the output value is greater than the specified width, or if width isn't given, all characters of the value are output, subject to the precision specification.

If the width specification is an asterisk (*), an int argument from the argument list supplies the value. The width argument must precede the value that's being formatted in the argument list, as shown in this example:

printf("%0*d", 5, 3); /* 00003 is output */

A missing or small width value in a conversion specification doesn't cause the truncation of an output value. If the result of a conversion is wider than the width value, the field expands to contain the conversion result.

Precision specification

In a conversion specification, the third optional field is the precision specification. It consists of a period (.) followed by a non-negative decimal integer that, depending on the conversion type, specifies the number of string characters, the number of decimal places, or the number of significant digits to be output.

Unlike the width specification, the precision specification can cause either truncation of the output value or rounding of a floating-point value. If precision is specified as 0, and the value to be converted is 0, the result is no characters output, as shown in this example:

printf( "%.0d", 0 ); /* No characters output */

If the precision specification is an asterisk (*), an int argument from the argument list supplies the value. In the argument list, the precision argument must precede the value that's being formatted, as shown in this example:

printf( "%.*f", 3, 3.14159265 ); /* 3.142 output */

The type character determines either the interpretation of precision or the default precision when precision is omitted, as shown in the following table.

How Precision Values Affect Type

TypeMeaningDefault
aAThe precision specifies the number of digits after the point.Default precision is 13. If precision is 0, no decimal point is printed unless the # flag is used.
cCThe precision has no effect.Character is printed.
diouxXThe precision specifies the minimum number of digits to be printed. If the number of digits in the argument is less than precision, the output value is padded on the left with zeros. The value is not truncated when the number of digits exceeds precision.Default precision is 1.
eEThe precision specifies the number of digits to be printed after the decimal point. The last printed digit is rounded.Default precision is 6. If precision is 0 or the period (.) appears without a number following it, no decimal point is printed.
fFThe precision value specifies the number of digits after the decimal point. If a decimal point appears, at least one digit appears before it. The value is rounded to the appropriate number of digits.Default precision is 6. If precision is 0, or if the period (.) appears without a number following it, no decimal point is printed.
gGThe precision specifies the maximum number of significant digits printed.Six significant digits are printed, and any trailing zeros are truncated.
sSThe precision specifies the maximum number of characters to be printed. Characters in excess of precision aren't printed.Characters are printed until a null character is encountered.

Argument size specification

In a conversion specification, the size field is an argument length modifier for the type conversion specifier. The size field prefixes to the type field—hhhjl (lowercase L), LlltwzI (uppercase i), I32, and I64—specify the "size" of the corresponding argument—long or short, 32-bit or 64-bit, single-byte character or wide character—depending on the conversion specifier that they modify. These size prefixes are used with type characters in the printf and wprintf families of functions to specify the interpretation of argument sizes, as shown in the following table. The size field is optional for some argument types. When no size prefix is specified, the formatter consumes integer arguments—for example, signed or unsigned charshortintlong, and enumeration types—as 32-bit int types, and floatdouble, and long double floating-point arguments are consumed as 64-bit double types. This behavior matches the default argument promotion rules for variable argument lists. For more information about argument promotion, see Ellipses and Default Arguments in Postfix expressions. On both 32-bit and 64-bit systems, the conversion specification of a 64-bit integer argument must include a size prefix of ll or I64. Otherwise, the behavior of the formatter is undefined.

Some types are different sizes in 32-bit and 64-bit code. For example, size_t is 32 bits long in code compiled for x86, and 64 bits in code compiled for x64. To create platform-agnostic formatting code for variable-width types, you can use a variable-width argument size modifier. Alternatively, use a 64-bit argument size modifier and explicitly promote the variable-width argument type to 64 bits. The Microsoft-specific I (uppercase i) argument size modifier handles variable-width integer arguments, but we recommend the type-specific jt, and z modifiers for portability.

Size Prefixes for printf and wprintf Format-Type Specifiers

To specifyUse prefixWith type specifier
char
unsigned char
hhdioux, or X
short int
short unsigned int
hdioux, or X
__int32
unsigned __int32
I32dioux, or X
__int64
unsigned __int64
I64dioux, or X
intmax_t
uintmax_t
j or I64dioux, or X
long doublel (lowercase L) or LaAeEfFg, or G
long int
long unsigned int
l (lowercase L)dioux, or X
long long int
unsigned long long int
ll (lowercase LL)dioux, or X
ptrdiff_tt or I (uppercase i)dioux, or X
size_tz or I (uppercase i)dioux, or X
Single-byte characterhc or C
Wide characterl (lowercase L) or wc or C
Single-byte character stringhsS, or Z
Wide-character stringl (lowercase L) or wsS, or Z

The ptrdiff_t and size_t types are __int32 or unsigned __int32 on 32-bit platforms, and __int64 or unsigned __int64 on 64-bit platforms. The I (uppercase i), jt, and z size prefixes take the correct argument width for the platform.

In Visual C++, although long double is a distinct type, it has the same internal representation as double.

An hc or hC type specifier is synonymous with c in printf functions and with C in wprintf functions. An lclCwc, or wC type specifier is synonymous with C in printf functions and with c in wprintf functions. An hs or hS type specifier is synonymous with s in printf functions and with S in wprintf functions. An lslSws or wS type specifier is synonymous with S in printf functions and with s in wprintf functions.

 Note

Microsoft-specific: The I (uppercase i), I32I64, and w argument size modifier prefixes are Microsoft extensions and are not ISO C-compatible. The h prefix when it's used with data of type char and the l (lowercase L) prefix when it's used with data of type double are Microsoft extensions.

相关文章:

  • c++ 如何给数组批量赋值--利用结构定义数组以提高程序的可读性
  • c++ windows 之下 CreateThread vs CreateProcess
  • libusb源码学习:list_entry
  • libusb源码学习:几个函数加载的宏(windows)
  • MCU_如何通过硬件VID 查找生产厂家
  • MCU_WireShark USB抓包内容解析
  • MCU_Wireshark USB 抓包过滤(抓特定端口地址)
  • STM32F4xx usb库源码详解 custom HID
  • STM32F4xx usb库源码详解:HAL_PCDEx_SetRxFiFo 和 HAL_PCDEx_SetTxFiFo
  • Libuv 1.34.2 源码详解 ---- 以uvCat为例讲解
  • 步进电机的细分驱动中1-2相, W1-2相, 2W1-2相, 4W1-2相 表示什么意思?
  • MCU_关于STM32Fxxx中断EXTI产生时多次(两次)进入中断的原因
  • MCU_通过windows串口API控制RTS和DTR
  • MCU_STM32的HAL库中的宏DMA_FLAG_TCIF0_4/DMA_FLAG_TCIF1_5/DMA_FLAG_TCIF2_6/DMA_FLAG_TCIF3_7
  • LWIP_TCP如何理解数据发送,何时使用tcp_recved函数
  • 自己简单写的 事件订阅机制
  • crontab执行失败的多种原因
  • css系列之关于字体的事
  •  D - 粉碎叛乱F - 其他起义
  • github指令
  • IOS评论框不贴底(ios12新bug)
  • JS数组方法汇总
  • linux学习笔记
  • Material Design
  • mysql 数据库四种事务隔离级别
  • Mysql优化
  • node.js
  • passportjs 源码分析
  • Promise面试题,控制异步流程
  • Vue实战(四)登录/注册页的实现
  • 日剧·日综资源集合(建议收藏)
  • 如何抓住下一波零售风口?看RPA玩转零售自动化
  • 首页查询功能的一次实现过程
  • 算法之不定期更新(一)(2018-04-12)
  • 通过npm或yarn自动生成vue组件
  • 关于Android全面屏虚拟导航栏的适配总结
  • ​软考-高级-信息系统项目管理师教程 第四版【第19章-配置与变更管理-思维导图】​
  • #define 用法
  • $.extend({},旧的,新的);合并对象,后面的覆盖前面的
  • (13)Latex:基于ΤΕΧ的自动排版系统——写论文必备
  • (C++)栈的链式存储结构(出栈、入栈、判空、遍历、销毁)(数据结构与算法)
  • (html5)在移动端input输入搜索项后 输入法下面为什么不想百度那样出现前往? 而我的出现的是换行...
  • (动手学习深度学习)第13章 计算机视觉---图像增广与微调
  • (切换多语言)vantUI+vue-i18n进行国际化配置及新增没有的语言包
  • (算法)求1到1亿间的质数或素数
  • (一)pytest自动化测试框架之生成测试报告(mac系统)
  • (转)C语言家族扩展收藏 (转)C语言家族扩展
  • .NET Micro Framework初体验
  • .NET基础篇——反射的奥妙
  • .NET简谈设计模式之(单件模式)
  • /usr/bin/perl:bad interpreter:No such file or directory 的解决办法
  • @Autowired 与@Resource的区别
  • @JsonSerialize注解的使用
  • [ 云计算 | Azure 实践 ] 在 Azure 门户中创建 VM 虚拟机并进行验证
  • [14]内置对象