.com.unity Forums

.com.unity Forums (http://forum.shrapnelgames.com/index.php)
-   Dominions 2: The Ascension Wars (http://forum.shrapnelgames.com/forumdisplay.php?f=55)
-   -   2.08 and Incompatible Battle Reports (http://forum.shrapnelgames.com/showthread.php?t=17878)

Taqwus February 26th, 2004 05:45 PM

Re: 2.08 and Incompatible Battle Reports
 
alexti --
If memory serves, there's no standard way to specify to a compiler that a given C function has no side-effects. Function calls should not be automatically collated unless the code is inlined, in which case it may be possible. There might be a way to search the transitive closure of a function, so long as the closure resides within a given source file, for unsafe operations (assignments to non-local variables, assorted pieces of assembler, function calls outside file, I/O...) but that would seem like an awful headache for a compiler designer to consider in light of the fact that the original programmer could easily handle the job himself by calling the function once and assigning the result to a variable, then assigning a second variable the same value as the first.

E. Albright February 26th, 2004 08:33 PM

Re: 2.08 and Incompatible Battle Reports
 
Quote:

Originally posted by alexti:
Some Languages consider line feeds as a language element, but not C/C++.
</font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">f(); f();</pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">and
</font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">f();
f();</pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">are the same thing.

<font size="2" face="sans-serif, arial, verdana">Fair enough. However, Arryn was suggesting that your example was not analogous because the calls were in seperate statements (tho' to be fair, she used the term "lines", so the confusion is understandable). Based on presented pseudocode, JK's code at the time was supposed to resemble </font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> f() + f(); </pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">whereas your example was more akin to
</font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">p = f();
q = f();
r = p + q; </pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">so your example could be deemed irrelevant. However, JK subsequently revealed the actual structure of the code, and thus demonstrated that your example was actually more analogous to it than the previously suggested Version. So my pedantic objection to your example is at least as irrelevant, if not more so... http://forum.shrapnelgames.com/image...s/rolleyes.gif

E. Albright February 26th, 2004 08:51 PM

Re: 2.08 and Incompatible Battle Reports
 
Quote:

Originally posted by alexti:
I understand that you're talking about the functions which are function in mathematic sense, meaning that for a given set of arguments the result will always be the same, and the return value will be the only data that will be changed.
I don't know if there's a term for such functions.

<font size="2" face="sans-serif, arial, verdana">A function without side effects would be a referentially transparent function.

[Edit: re-read what I'd misread. Deleted half of my post.]

[ February 26, 2004, 18:58: Message edited by: E. Albright ]

Arryn February 26th, 2004 08:54 PM

Re: 2.08 and Incompatible Battle Reports
 
Quote:

Originally posted by alexti:
The idea of the standards is to be able to write code which will work correctly (meaning that as programmer specified in the source code - as opposite to what the programmer wants http://forum.shrapnelgames.com/images/icons/icon12.gif ) if compiled by any standard-compliant compiler.
<font size="2" face="sans-serif, arial, verdana">The C/C++ standards do not address the issue that's been the focus of this interminable discussion. So your argument is sort of irrelevant.
Quote:

Optimizer should meet all criteria defined in the language standard concerning the produced binary code, so the only case when it is allowed to alter the results is when the programmer is using constructs which behaviour is undefined by the standard. And the programmer should not be using such constructs.
<font size="2" face="sans-serif, arial, verdana">1) The compiler does comply with the standard. 2) The side effect is not anticipated by the standards. 3) The construct is perfectly legal. But it assumes things. Bad things. (An analogy is writing code that depends on the bit-order of the hardware it's running on. A real bad no-no.) It's the responsibility of programmers to understand what their code is intended to do, and how the compiler will do its task, and whether there's a conflict between his/her intentions and its results. It's not the job of standards to protect programmers from themselves. (That's what good teachers, lots of reading, and not getting in the habit of sloppy coding is for. http://forum.shrapnelgames.com/images/icons/icon12.gif )

Arryn February 26th, 2004 08:57 PM

Re: 2.08 and Incompatible Battle Reports
 
Quote:

Originally posted by E. Albright:
Oh, and a function without side effects would be a referentially transparent function.
<font size="2" face="sans-serif, arial, verdana">Thank you. That's the term I'd been wracking my brain to remember. Optimizers assume functions are referentially transparent. It's the responsibility of programmers to compensate ...

Gandalf Parker February 26th, 2004 10:43 PM

Re: 2.08 and Incompatible Battle Reports
 
DISCLAIMER Im just kidding.

There are no mismatched battle reports. You all just have cowardly messengers. "Ummm you won. Yeah thats it, YOU WON oh Mighty and Frightening Deity."

I dont have that problem. But then I usually take wimply little mages. I dont take big scarey two-headed snakes, or giant floating heads.

[ February 26, 2004, 20:47: Message edited by: Gandalf Parker ]

alexti February 27th, 2004 02:13 AM

Re: 2.08 and Incompatible Battle Reports
 
Quote:

Originally posted by Arryn:
</font><blockquote><font size="1" face="sans-serif, arial, verdana">quote:</font><hr /><font size="2" face="sans-serif, arial, verdana">Originally posted by alexti:
The idea of the standards is to be able to write code which will work correctly (meaning that as programmer specified in the source code - as opposite to what the programmer wants http://forum.shrapnelgames.com/images/icons/icon12.gif ) if compiled by any standard-compliant compiler.

<font size="2" face="sans-serif, arial, verdana">The C/C++ standards do not address the issue that's been the focus of this interminable discussion. So your argument is sort of irrelevant.</font><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">That's exactly the point. If C/C++ standard does not specify the order of evaluation (I haven't seen it there, but it doesn't mean that it's not there though http://forum.shrapnelgames.com/images/icons/icon7.gif ) you can not rely on any particular order.
In the following example you can't rely on whether left call or right call will be evaluated first, but you can rely that both of them will be evaluated.
</font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> int print_empty_line()
{
printf(&quot;\n&quot;);
return 1;
}

void foo(int x)
{
if (x + print_empty_line() &lt; 2 + print_empty_line())
...
}</pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">
Quote:

</font><blockquote><font size="1" face="sans-serif, arial, verdana">quote:</font><hr /><font size="2" face="sans-serif, arial, verdana">Optimizer should meet all criteria defined in the language standard concerning the produced binary code, so the only case when it is allowed to alter the results is when the programmer is using constructs which behaviour is undefined by the standard. And the programmer should not be using such constructs.
<font size="2" face="sans-serif, arial, verdana">1) The compiler does comply with the standard.
</font><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">Which case you considering? Concerning evaluation order it's standard-compliant, but if it replaces 2 calls with one, it's not.

alexti February 27th, 2004 02:21 AM

Re: 2.08 and Incompatible Battle Reports
 
Quote:

Originally posted by E. Albright:
</font><blockquote><font size="1" face="sans-serif, arial, verdana">quote:</font><hr /><font size="2" face="sans-serif, arial, verdana">Originally posted by alexti:
Some Languages consider line feeds as a language element, but not C/C++.
</font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">f(); f();</pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">and
</font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">f();
f();</pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">are the same thing.

<font size="2" face="sans-serif, arial, verdana">Fair enough. However, Arryn was suggesting that your example was not analogous because the calls were in seperate statements (tho' to be fair, she used the term "lines", so the confusion is understandable).
</font><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">Here's where those examples came from:
Quote:

Originally posted by Arryn:
[qb]The problem comes in that the compiler's optimization will substitute the same call to the random number function for both die rolls. It won't make the two rand() calls the coders intend. What it does is make one call and plug the same value into both places. The optimizer does not know that in this circumstance, two calls to the same function do not return the same value.
<font size="2" face="sans-serif, arial, verdana">And in all 3 cases f shall be called twice:
</font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> f(); f();

f(), f();

f()+f()</pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">Edit: Fixed quotations. Again.
P.S. I want real forum/client http://forum.shrapnelgames.com/images/icons/icon12.gif

[ February 27, 2004, 00:23: Message edited by: alexti ]

Gandalf Parker February 27th, 2004 04:06 PM

Re: 2.08 and Incompatible Battle Reports
 
OK master password is in now, but has anyone tried using it? I take it that it is only to override the player passwords? No AI access? I was hoping it would let me jump in midgame to check on what an AI was doing.

General Tacticus February 27th, 2004 05:26 PM

Re: 2.08 and Incompatible Battle Reports
 
Quote:

Originally posted by Gandalf Parker:
DISCLAIMER Im just kidding.

There are no mismatched battle reports. You all just have cowardly messengers. "Ummm you won. Yeah thats it, YOU WON oh Mighty and Frightening Deity."

I dont have that problem. But then I usually take wimply little mages. I dont take big scarey two-headed snakes, or giant floating heads.

<font size="2" face="sans-serif, arial, verdana">My messengers wouldn't dare report anything but the Truth ! First, it is official dogma that I, as a Pretender, am All-Knowing, therefore any effort at lying will be found out. And all my citizens are true believers of official dogma. Second, it is equally well known that bad news only result in a quick and painful death, while lying result in an eternal and even more painful afterlife. And finally, my majordomo knows that I don't like to be bothered by unsignificant events...

Of course, it helps that I never lose a battle, and that there are never bad news to report. And it helps that I have a first-class majordomo.

(Tacticus Sanguinus, God of Mictlan)


All times are GMT -4. The time now is 08:36 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.