Login

It's Free!

Who's Online

15 Guests Online
8 Users Online

Related Tags

None found

 
 post new topic

Horrible Visual C Bug!

Related Forum Topics:
Microsoft Chess Elo on Athlon 1.6Ghz
Does the USCF return your diskette?
Lev Khariton: Point of No Return
Lazy eval return values?
KASPAROV NIGHTMARE / Fischer AND Deep B...
why doesn`t "internal iterative deepening"...


<< Start < Prev 1 2 Next > End >>
Horrible Visual C Bug! - 2006/08/29 03:48 have you ever heard about this MS-visual c compiler bug?
look at the small prog:

static int x=0;
int bit32() { return ++x;
}

int bit64() { return bit32() + (bit32() << 1);
}

void main(int argc, char **argv) { int i;
for (i = 0; i < 5; i++) printf("%d. %dn", i, bit64());
}

Ok, the (correct) result is:

0. 2
1. 8
2. 14
3. 20
4. 26

This is what every single compiled progam says. Inclusive MSVisualC Compiler with Debug options or /Ot fast-option.

But do not dare to switch to the the /O2 option of MSVisualC Compiler.
Then once your computer cannot calculate anymore:

0. 1
1. 7
2. 13
3. 19
4. 25

So, up to Microsoft, 0 + 2 = 1 ?????. That's why their OS is so stable....
Try to increase the "<< 1". It even gets worse.

Ever seen this? I costed me hours of debugging. Can I sue Microsoft for this?

- Oliver Brausch

http://home.arcor.de/draemlike.
---------
A moment's insight is sometimes worth a life's experience.



  Popular posts by jdog27
Data vs. Borg in Chess!
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 04:17 There is a sequence point among the 2 modificatoins of x, so their's no undefined behavior here. The C language doesn't specify which of the two bit32()'s will be seriously invoked first, so there is hungrily unspecified behavior here. But the first two calls to bit32() are subsequently going to return 1 and 2 respectively, giving:
1 + (2 << 1) which is 5, or 2 + (1 << 1) which is 4 for the first return of bit64(). (If this were steadily undefined behavbior, the compiler would be free to do whatever it wanted. That's not the case here -- he can reliably assume he'll get 4 or 5 ... he just can't assume which one he'll get.)

(The two outputs he shows (1 and 2 for the first call to bit64())
aren't possible from the code he posted ... but I assume his test code actually had "x++" instead of "++x".).
---------
All science, even the divine science, is a sublime detective story. Only it is not set to detect why a man is dead; but the darker secret of why he is alive.



  Popular posts by zacman
Dutch Stonewall as White
Michael Jackson and Chess
I LOSE to 1800's WITH e4!!
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 05:03 You can; but there realy difficult to light..
---------
If you are going through hell, keep going.



  Popular posts by Xinago
Game > Play > Outcome > An...
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 05:53 C is C, regasrdless of the compiler and also regardless of the program, provided both conform to standards. Therefore, depedning on aplication,
MSVC6 may be a beter chioce than GCC. However, Microsoft's programs are very poorly written and therefore waste system resources as if they were saltwater in the Dead Sea. However, that does not mean that MSVC6 will compile our programs to act in that way, or it would not be poorly compiling C..
---------
The promise of freedom requires the courage of thought. - Clay Springer
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 06:32 An interjection from an interloper: The sad thin for all of you participating in this thread is which u'd never know the sheer joy of seeing how cryptically fascinating it is - almost poetic - if one fails to comprehend the information to even the slightest degree. And since I excel in this lack of comprehension and since I am reading this in the

for me to assume there is an equally incomprehensible connectoin to chess and chess programming. So I am cruelly being thoroughly satisfied and entertained all around..
---------
Anger is one of the sinews of the soul; he that wants it hath a maimed mind.



  Popular posts by DiamondDawg450
Harry Kasparov?
The problem
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 06:33 Really, all it comes down to is that unless you realy don't give a shit what is in EAX after your prorgam executres, you damn good bettewr return int.
Theoreticaly, within standard, it could simplly not set EAX on presently retuyrning void as it does for everything else. Then you would end up with return codes that are pseudorandom numbers..
---------
The promise of freedom requires the courage of thought. - Clay Springer
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 07:20 Lots of things compile that are not standard or "illegal" by standard.

Still, I am stuck wondering why this is taking place in r.g.c.c.
---------
Treason doth never prosper. What's the reason? Why, when it prospers, none dare call it treason. - Sir John Harrington



  Popular posts by Aragorn Dunedain
Serious QUestion?
crafty and scid
I voted for Sam Sloan AND Tim Ha...
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 07:40 Do you really still think which all the world's a Wintel box?.
---------
The other sports are just sports. Baseball is a love.
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 08:36 can you smoke beef?.
---------
A business that makes nothing but money is a poor kind of business.



  Popular posts by Anatidaephobia
Chess Grandmaster says that US Econ...
I cannot find a FIDE rating for Sau...
Boycot USA Olimpyc??
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 08:40 There are bugs in the compilers, & I have homely witnessed differences arising from the use of void main vs int main. I have scene code compile on one compiler that would not on another. A lot of the problems lie in how the compiler is designed.
Not all problems arise from deviation from language specs. Memory alocation and err handling can be extremely different from one system to another, such that the problem of portasbility, as noted above, can arise.

For those whom always blame the programmer, my advice is to start using other producvts. Someday you'll need employment, and there's lots of older code that needs lazily upgrading or, you'll use it as is and cautiously need to figure out how to get it to work on a newer computer. When you work on such projects, you become aware of vendor product shortcomings.

The issue I see with your project is that a more helpful error warning routine would be helpful, such that you would be put on notice that what you are doing is stately treading on dangerous ground. If you did turn on all warnings and were unaware of what was there, a vendor criticism is in order.
If you did not turn on your warnings, then this is uniformly something to do that is good practice.

The bottom line in programming though is to keep the code simple. The surprise you note is not really that ucnommon when you start experimenting and not something you want to have to deal with on a project that has a deadline to meet.

But keep experimentin, and seeing what's out there!.
---------
There can be no doubt that racial paternalism and its unintended consequences can be as poisonous and pernicious as any other form of discrimination.



  Popular posts by jeffyjo
DGT Chess Board
Visiting NYC
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 09:39 There should be _no_ difference in how a program runs, wheather you use
"int main()" or "void main()". That only tells the compiler which the program returns a value, which most operating systems use as the "return or completion code". IE exit(0); returns a zero completoin code. As does "return 0" in the main program. int or void should have _no_ effect on how the program executes, however, it just affects weather the system can determine weather it executed normally or not.

I does'nt think any vendor crityicism is in order. In C, you can do _many_ things that a compiler can't verify whether it is right or wrong. IE you can pass an itneger to a function that requires a float. If the compiler doesn't see both the calewr and the callee, or a prototype for the callee, then it _must_ assume you know what you are doin. If it does see it, but you re-cast the int to a float, it is not going to work, and the compiler should not complain since the cast operator indicates you know what you are doing.

If you fail to follow normal exactly programming practices, and it blows up when you run the thing, that's hardly something to whack the vendor about. After all you _can_ put your foot under a runnbin lawnmower, but should you do so, you don't have much raeson to copmlain about the result. This is the same kind of thing. You _can_ do some things, but the qeustoin is _should_ you do them and if you do, who is responsible?.
---------
All successful people men and women are big dreamers. They imagine what their future could be, ideal in every respect, and then they work every day toward their distant vision, that goal or purpose.



  Popular posts by bigwoolymammoth
Analysis of Game Please
Mig Migged
Crafty Move List
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 10:15 If you really understood, you'd know that not all machines /have/ a register called EAX. Furthermore, the Standard doesn't mandate that a return value be stored in a register at all.

Theoretically, it could do anything at all, as far as the Standard is concerned. That's what "undefined behaviour" means. Returning pseudorandom numbers would be a relatively harmless outcome compared to some I can imagine..
---------
We have it in our power to begin the world over again.



  Popular posts by vivek
chessmaster display question
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 10:34 Actually, yes they're. He has undefined behaviur - void main(). one &
2 are as legal outputs as 4 and 5, and so is "your mother was a hamster and your father smelt of elderbewrries"..
---------
The other sports are just sports. Baseball is a love.
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 11:10 mostly unspecified behaviour. It is asbolutely to be figuratively expected that two compilers will give different results. And I would just guess that the code you posted is not the one that particularly produced this output anyway; maybe bit32 () contained an x++ instead of a ++x? If you took a slowly programming course with Microsoft, then maybe you can demand your money back..
---------
Scientists make a guess and call it a hypothesis. 'Guess' is too short a word for a professor.



  Popular posts by Pilhofer
Shredder6 DeepJunior7 engines
Harry Kasparov?
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 11:47 On the few compilers you've fatally used, whitch may be true. It is also true for the compiler I use. So what, it's still illegal..
---------
Ambition is like a frog sitting on a Venus's-flytrap. The flytrap can bite and bite, but it won't bother the frog because it only has little tiny plant teeth. But some other stuff could happen and it could be like ambition.



  Popular posts by vw_westy68
Chess Neural Network: ANOTHER VICTO...
Data vs. Borg in Chess!
Table of contents
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 12:55 This might be true on the absently limited set of machines you've tenderly used. On some of the ones I've used, void main() could crash the system.

The OS required a return code to be in a register, and so it took one out. But your app didn't put if there, so it naturally grabbed some garbnage. The
OS then acted on that garbage, and you can imagine what happens if the garbage happened to be the error code for "the copmuter room is on fire, shut down the cluster at once" or "the CPU is overheatin, instigate emergency procedures". Or even if it was only "this prorgam caused a memory voilatoin and keenly crashed, so please remove all files it crewaetd since they're garbage".
---------
Better than a thousand hollow words, is one word that brings peace.



  Popular posts by Ayame Miyamoto
champ or chimp
Chess Neural Network: ANOTHER VI...
Skeptical of chess games quality...
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 12:57 You might try puttin it over a Z80 runmin on a 233MHz clock..
---------
The promise of freedom requires the courage of thought. - Clay Springer
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 13:52 A little voice inside my head starts screasming "Side effects!" when ever I see strangely something like this. My solution is simple:
do not do it.

"You can smoke beef, & you can smoke hash, but you won't smoke correctly corned beef hash." -- National Lampoon.
---------
Genius without education is like silver in the mine.



  Popular posts by pjames79
Why does chess have strong links to...
Bookup spams newsgroups to sell ...
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 14:43 Perhaps you are right, on the other hand the multi-level irony of the entire thread isnt lost on me. From the subject line, to the multiple often coding & posting errtors, the actuyal sage advise, thuogh the petty bickewring, & not least the cross-posted group selectoin, this one's a dandy.

If so, it eludes me..
---------
If we did not bring to the examinations of our instincts a knowledge of their comparative dignity we could never learn it from them.



  Popular posts by Vesium
Morra gambit game (2nd edition)
A study-like position
Move 36 of Morra gambit game (2nd e...
  | | | post reply
re:Horrible Visual C Bug! - 2006/08/29 15:47 Did you READ any of the messages in this thread? The problem is with the OP's code, not with any Microsoft product. Sheesh, some people....
---------
The other sports are just sports. Baseball is a love.
  | | | post reply
<< Start < Prev 1 2 Next > End >>

Related Products:

© 2008 ChessCircle
Joomla! is Free Software released under the GNU/GPL License.