|
|
|
|
|
February 26th, 2004, 05:45 PM
|
|
Major General
|
|
Join Date: Aug 2000
Location: Mountain View, CA
Posts: 2,162
Thanks: 2
Thanked 4 Times in 4 Posts
|
|
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.
__________________
Are we insane yet? Are we insane yet? Aiiieeeeee...
|
February 26th, 2004, 08:33 PM
|
Second Lieutenant
|
|
Join Date: Sep 2000
Location: Ohio, USA
Posts: 454
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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++.
code:
f(); f();
and
code:
f();
f();
are the same thing.
|
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 code:
f() + f();
whereas your example was more akin to
code:
p = f();
q = f();
r = p + q;
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...
|
February 26th, 2004, 08:51 PM
|
Second Lieutenant
|
|
Join Date: Sep 2000
Location: Ohio, USA
Posts: 454
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
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 ]
|
February 26th, 2004, 08:54 PM
|
|
Major General
|
|
Join Date: Jan 2004
Location: twilight zone
Posts: 2,247
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 ) if compiled by any standard-compliant compiler.
|
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.
|
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. )
|
February 26th, 2004, 08:57 PM
|
|
Major General
|
|
Join Date: Jan 2004
Location: twilight zone
Posts: 2,247
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
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 ...
|
February 26th, 2004, 10:43 PM
|
|
Shrapnel Fanatic
|
|
Join Date: Oct 2003
Location: Vacaville, CA, USA
Posts: 13,736
Thanks: 341
Thanked 479 Times in 326 Posts
|
|
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 ]
__________________
-- DISCLAIMER:
This game is NOT suitable for students, interns, apprentices, or anyone else who is expected to pass tests on a regular basis. Do not think about strategies while operating heavy machinery. Before beginning this game make arrangements for someone to check on you daily. If you find that your game has continued for more than 36 hours straight then you should consult a physician immediately (Do NOT show him the game!)
|
February 27th, 2004, 02:13 AM
|
First Lieutenant
|
|
Join Date: Dec 2003
Location: Calgary, Canada
Posts: 762
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: 2.08 and Incompatible Battle Reports
Quote:
Originally posted by Arryn:
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 ) if compiled by any standard-compliant compiler.
|
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. 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 ) 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.
code:
int print_empty_line()
{
printf("\n");
return 1;
}
void foo(int x)
{
if (x + print_empty_line() < 2 + print_empty_line())
...
}
Quote:
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.
|
1) The compiler does comply with the standard.
Which case you considering? Concerning evaluation order it's standard-compliant, but if it replaces 2 calls with one, it's not.
|
February 27th, 2004, 02:21 AM
|
First Lieutenant
|
|
Join Date: Dec 2003
Location: Calgary, Canada
Posts: 762
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: 2.08 and Incompatible Battle Reports
Quote:
Originally posted by E. Albright:
quote: Originally posted by alexti:
Some Languages consider line feeds as a language element, but not C/C++.
code:
f(); f();
and
code:
f();
f();
are the same thing.
|
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).
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.
|
And in all 3 cases f shall be called twice:
code:
f(); f();
f(), f();
f()+f()
Edit: Fixed quotations. Again.
P.S. I want real forum/client
[ February 27, 2004, 00:23: Message edited by: alexti ]
|
February 27th, 2004, 04:06 PM
|
|
Shrapnel Fanatic
|
|
Join Date: Oct 2003
Location: Vacaville, CA, USA
Posts: 13,736
Thanks: 341
Thanked 479 Times in 326 Posts
|
|
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.
__________________
-- DISCLAIMER:
This game is NOT suitable for students, interns, apprentices, or anyone else who is expected to pass tests on a regular basis. Do not think about strategies while operating heavy machinery. Before beginning this game make arrangements for someone to check on you daily. If you find that your game has continued for more than 36 hours straight then you should consult a physician immediately (Do NOT show him the game!)
|
February 27th, 2004, 05:26 PM
|
Sergeant
|
|
Join Date: Dec 2003
Posts: 201
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
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)
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
|
|