www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - code generation bug?

↑ ↓ ← Scott Mayo <Scott_member pathlink.com> writes:
My first day using dmc. I fed it some C++ code that was known to be
well-behaved; the resulting .exe crashed. I couldn't get the assembler listing
working, but I was able to move code and get the correct behaviour.  

The crashing code:

switch (p->cmd) //dies around here
{
case CMD_Set:
setpins(p->pinset, p->set.onV);
return 0;

case CMD_SetFreq:
for (i = 0; i < 5; ++i)
..etc


The working code, which is equivalent:

//DigitalMars compiler generates a jump to address 0
//if this is a case in the switch
//no problem as an If, though.
#if 01
if (p->cmd == CMD_Set)
{
setpins(p->pinset, p->set.onV);
return 0;
}
#endif

switch (p->cmd)
{
case CMD_Set:
setpins(p->pinset, p->set.onV);
return 0;

case CMD_SetFreq:
for (i = 0; i < 5; ++i)


I'm new here - does anyone do support? I can make the source available; the
compile command line was just 
dmc mycode.cpp

The code uses no explicit new/delete/malloc/stl/iostreams/overloading or any
interesting trickery. There is some inline asembler, but when I compile and run
it as a console app using the microsoft IDE, that same assmbler runs just fine,
so I don't think it's doing any damage. Really looks like a compiler issue to
me. Help?

Another trick that worked, then the code was part of the switch statement, was
to put a fprintf in the case. 
Mar 17 2006
↑ ↓ Heinz Saathoff <newshsaat arcor.de> writes:
Hello,

Scott Mayo wrote...
 My first day using dmc. I fed it some C++ code that was known to be
 well-behaved; the resulting .exe crashed. I couldn't get the assembler listing
 working, but I was able to move code and get the correct behaviour.  
 
 The crashing code:
 
 switch (p->cmd) //dies around here
 {
 case CMD_Set:
 setpins(p->pinset, p->set.onV);
 return 0;
 
 case CMD_SetFreq:
 for (i = 0; i < 5; ++i)
 ..etc

Mybe an uninitialized pointer p? What makes me think it's this kind of error is that your code works when adding the extra statements. I know that adding/deleting portions of code can influence the data arrangement on the stack and make uninitialized pointers crash/not crash the program. - Heinz
Mar 20 2006
↑ ↓ → Scott Mayo <Scott_member pathlink.com> writes:
Mybe an uninitialized pointer p? What makes me think it's this kind of 
error is that your code works when adding the extra statements. 

No, but it was my error - I went off the end of an array and clobbered the first entry of the switch jump table. The compiler is not to blame.
Mar 20 2006