-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathOctalLiteral.qhelp
More file actions
45 lines (34 loc) · 1.33 KB
/
OctalLiteral.qhelp
File metadata and controls
45 lines (34 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>An integer literal consisting of a leading <code>0</code> digit
followed by one or more digits in the range <code>0-7</code> is an
octal literal. This can lead to two problems:</p>
<ul>
<li>An octal literal can be misread by a programmer as a decimal literal.</li>
<li>A programmer might accidentally start a decimal literal with a zero, so that the compiler
treats the decimal literal as an octal literal. For example, <code>010</code> is equal to
<code>8</code>, not <code>10</code>.</li>
</ul>
</overview>
<recommendation>
<p>To avoid these problems:</p>
<ul>
<li>Avoid using octal literals so that programmers do not confuse them with decimal literals.
However, if you need to use octal literals, you should add a comment to each octal literal
indicating the intention to use octal literals.</li>
<li>When typing decimal literals, be careful not to begin them with a zero accidentally.</li>
</ul>
</recommendation>
<references>
<li>
J. Bloch and N. Gafter, <em>Java Puzzlers: Traps, Pitfalls, and Corner Cases</em>, Puzzle 59. Addison-Wesley, 2005.
</li>
<li>
Java Language Specification:
<a href="https://docs.oracle.com/javase/specs/jls/se11/html/jls-3.html#jls-3.10.1">Integer Literals</a>.
</li>
</references>
</qhelp>