<< |  >>
#6403 Dodano: 24-11-2012 12:32. Głosów: 95
post z r/lolphp:

0x0 wat by Altreus (self.lolphp)
>>> 0x0 +2
4
>>> 0x0 +3.5
6.5
>>> 0x0 +2e1
757
:|

Here is an explanation I was provided with:
<mauke> once their lexer detects "0x", it skips all '0's, then calls strtol()
<mauke> so: tokptr = "0x0 +2;", toklen = 3
<mauke> skip 0x: tokptr = "0 +2;", toklen = 1
<mauke> skip all '0's: tokptr = " +2;", toklen = 0
<mauke> call strtol(" +2", NULL, 16) ==> 2
<mauke> then it proceeds to parse the remaining program starting from " +2;"
because that's where the previous token ends
<mauke> and this is how 0x0 ends up having the value 2
<mauke> 0x0 +2e1 ends up being 757 because the first pass interprets 2e1 as a hex integer
while the second pass thinks it's a floating point number
<mauke> so it's really 0x2e1 + 2.0e1
<< |  >>