aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-02-06 21:15:19 -0600
committerRob Landley <rob@landley.net>2012-02-06 21:15:19 -0600
commitb4a0efa8533f206e5c94a5872d251866c5f19265 (patch)
tree8e45e74b1b98b5ec53282d2fcf4d045e41713085
parent44a36ea927734f58b09eda59794eb1433a9f4401 (diff)
downloadtoybox-b4a0efa8533f206e5c94a5872d251866c5f19265.tar.gz
Document that optflags is always an int (so 32 bit and 64 bit platforms behave the same).
-rw-r--r--www/code.html17
1 files changed, 11 insertions, 6 deletions
diff --git a/www/code.html b/www/code.html
index 6eacb40d..2b2f392e 100644
--- a/www/code.html
+++ b/www/code.html
@@ -528,9 +528,9 @@ top to bottom in DECLARE_GLOBALS().</p>
<p>Each option in the optflags string corresponds to a bit position in
toys.optflags, with the same value as a corresponding binary digit. The
rightmost argument is (1<<0), the next to last is (1<<1) and so on. If
-the option isn't encountered while parsing argv[], its bit remains 0.
-(Since toys.optflags is a long, it's only guaranteed to store 32 bits.)
-For example,
+the option isn't encountered while parsing argv[], its bit remains 0.</p>
+
+<p>For example,
the optflags string "abcd" would parse the command line argument "-c" to set
optflags to 2, "-a" would set optflags to 8, "-bd" would set optflags to
6 (I.E. 4|2), and "-a -c" would set optflags to 10 (2|8).</p>
@@ -539,6 +539,12 @@ optflags to 2, "-a" would set optflags to 8, "-bd" would set optflags to
string "a*b:c#d", d=1, c=2, b=4, a=8. The punctuation after a letter
usually indicate that the option takes an argument.</p>
+<p>Since toys.optflags is an unsigned int, it only stores 32 bits. (Which is
+the amount a long would have on 32-bit platforms anyway; 64 bit code on
+32 bit platforms is too expensive to require in common code used by almost
+all commands.) Bit positions beyond the 1<<31 aren't recorded, but
+parsing higher options can still set global variables.</p>
+
<p><b>Automatically setting global variables from arguments (union this)</b></p>
<p>The following punctuation characters may be appended to an optflags
@@ -576,9 +582,8 @@ this[0]=42; and "-b 42" would set this[1]="42"; each slot is left NULL if
the corresponding argument is not encountered.</p>
<p>This behavior is useful because the LP64 standard ensures long and pointer
-are the same size, and C99 guarantees structure members will occur in memory
-in the
-same order they're declared, and that padding won't be inserted between
+are the same size. C99 guarantees structure members will occur in memory
+in the same order they're declared, and that padding won't be inserted between
consecutive variables of register size. Thus the first few entries can
be longs or pointers corresponding to the saved arguments.</p>