home home

downloads files

forum forum

docs docs

wiki wiki

faq faq

Cube & Cube 2 FORUM


VC++ 6.0 epic failure on some cube2 code

by lordofspace on 08/08/2009 08:56, 0 messages, last message: 08/08/2009 08:56, 938 views, last view: 04/25/2024 00:30

This doesn't have much to do with Sauerbraten per se, but rather with some of its code. The code is in tools.h, which I have used in one of my own projects. I recently had the misfortune of migrating my project into Visual C++ 6.0 for a friend of mine and ran across this gem in the custom vector class:

void drop() { buf[--ulen].~T(); }

which setsize(int) compiles to ->

mov eax, [ecx+8]
mov ecx, [esp+arg_0]
cmp eax, ecx
jle short locret_1000839D
loc_1000839B:
jmp short loc_1000839B
locret_1000839D:
retn 4

For the assembler uninclined, allow me translate back into c++ (note call to destructor was not present as this was for a type with trivial destructor):

void setsize(int x)
{
if(ulen <= x)
return;
while(1){}
}

Clearly not even close to correct!
If we change drop() to the following, everything is peachy keen:

void drop() { ulen--; buf[ulen].~T(); }

The asm generated in this case behaves exactly as expected.
Just thought I'd share this somewhat irrelevant but silly behavior of an ancient, but still used compiler.

   Board Index   


Unvalidated accounts can only reply to the 'Permanent Threads' section!


content by Aardappel & eihrul © 2001-2024
website by SleepwalkR © 2001-2024
53864400 visitors requested 71639544 pages
page created in 0.014 seconds using 10 queries
hosted by Boost Digital