本文介绍了是否有任何C ++风格指南谈论数字字面后缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有我读过的C ++风格的指南中,我从来没有见过关于数字字面后缀的任何信息(即 3.14f 0L 等)。

In all of the C++ style guides I have read, I never have seen any information about numerical literal suffixes (i.e. 3.14f, 0L, etc.).

问题


  1. Is there any style guide out there that talks about there usage, or is there a general convention?

我偶尔会遇到 f 后缀在图形编程中。在类型的编程域中是否存在使用趋势?

I occasionally encounter the f suffix in graphics programming. Is there any trend on there usage in the type of programming domain?


推荐答案

我没有发现一般的风格指南。我使用大写字母,我挑剔使用F为浮点文字和L为长双。我还为整数文字使用了适当的后缀。

There is no general style guide that I've found. I use capital letters and I'm picky about using F for float literals and L for long double. I also use the appropriate suffixes for integral literals.

我假设你知道这些后缀的含义: 3.14F a float literal,12.345是双字面值,6.6666L是长双字面值。

I assume you know what these suffixes mean: 3.14F is a float literal, 12.345 is a double literal, 6.6666L is a long double literal.

对于整数: code> U 是无符号 long LL long long U L 之间的顺序无关紧要,但我总是把 UL 因为我声明这样的变量 unsigned long 例如。

For integers: U is unsigned, L is long, LL is long long. Order between U and the Ls doesn't matter but I always put UL because I declare such variables unsigned long for example.

键入另一个类型的文字,或为另一个类型的函数参数提供一个类型的数字字面值。使用合适的后缀避免了这一点,并且沿着相同的线是有用的,因为static_cast对于调用cast是有用的。数字文字后缀的一致使用是好的风格,避免数字惊喜。

If you assign a variable of one type a literal of another type, or supply a numeric literal of one type for function argument of another type a cast must happen. Using the proper suffix avoids this and is useful along the same lines as static_cast is useful for calling out casts. Consistent usage of numeric literal suffixes is good style and avoids numeric surprises.

人们对于大小写是最好还是不同。选择一个看起来不错,风格一致的风格。

People differ on whether lower or upper case is best. Pick a style that looks good to you and be consistent.

这篇关于是否有任何C ++风格指南谈论数字字面后缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 18:57