On 25/02/2019 19:08, NY wrote:
> "Ahem A Rivet's Shot" wrote in message
> news:20190225142618.6663a9845e7fe4eb9c60ad89@eircom.net...
>> On Mon, 25 Feb 2019 12:29:38 +0000
>> Richard Heathfield wrote:
>>
>>> Which is the saving grace of Piet. Piet programs can be rather
>>> attractive.
>>
>> This program is pretty ...
>>
>> #define _ -F<00||--F-OO--;
>> int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
>> {
>> _-_-_-_
>> _-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_-_-_-_-_
>> _-_-_-_-_-_-_-_
>> _-_-_-_
>> }
>>
>>
>> ... but far from readable.
>
> I haven't a hope in hell of working out what it's supposed to do,
It's not that hard.
The first line defines the symbol "_" to expand to the second part.
We'll come back to that later.
The next line defines the global variables 'F' and 'OO', which are both
initialized to 0 (written as "00", but that's the same thing), and then
defines the main function.
The main function calls the function F_OO, then prints the result of
multiplying 4 by -F divided by OO divided (again) by OO. The dot beween
the 4 and the * turns the 4 into a floating-point number, which is
necessary for the printf format, but is otherwise uninteresting.
The function F_OO simply has several lines of the _ and - characters.
The latter is simply retained; the former gets expanded because it's a
macro.
_-_ would turn into:
|-----macro----| |-----macro----|
-F<00||--F-OO--;--F<00||--F-00--;
The minus between the two underscores gets prepended to the macro
expansion. However, macro expansion cannot turn a unary minus operator
into a prefix decrement operator, so that means that you should read the
second expansion as "-(-F)< 00".
As such, for every first expansion, the single unary minus there turns
the negative value in the F variable into a positive value (or it
remains at zero on the first line, which is also not negative and
therefore also triggers the logical or), which means that the F and OO
variable get decremented. They then get subtracted from one another, but
the result of that subtraction is not stored anywhere so it is thrown
away (or optimized away by most modern compilers).
For every second and later expansion of every line, the condition
"--F<00" must be true, and therefore the "--F-00--" part is not called.
So, every line, F is decremented once, and OO is decremented once.
There are 16 lines, so that must mean that at the end of the function,
both F and OO contain the value -16.
The result is that main calculates 4 * -(-16) / -16 / -16, which is 4 *
16 / -16 / -16, which is 4 / 16, which is indeed 0.25.
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|