elee24@castle.ed.ac.uk (H Bruce) (10/31/90)
I am having a problem with Microsoft C (V 5.1). When I pass a parameter of type float (by value) to a function, by the time it is read from the stack by the function it is corrupted. The corrupted value is something very small (eg X.XXXXe-XXX) and varies depending on the parameter. The program comprises 2000 lines of code in 7 modules producing a 90K EXE file. I am using the the large memory model. When I extract the offending part of the program and run it independently, the problem vanishes. This is happening in several functions. If I get around it by not passing parameters the problem manifests itself somewhere else. I have stack checking enabled. I have allocated 8K for the stack and there is over 1K free. (The stack size may sound a bit large but I pass some large structures as paramters.) Does anyone know what is is happening? How can I look at the stack in codeview ? How can I stop execution in codeview when the parameter is corrupted ? (This would have to be at assembly level I think ...... yeeeuuuch) Thanks in desperation, Henry Bruce.
brianh@hpcvia.CV.HP.COM (brian_helterline) (11/01/90)
elee24@castle.ed.ac.uk (H Bruce) writes: >I am having a problem with Microsoft C (V 5.1). >When I pass a parameter of type float (by value) to a function, by the time >it is read from the stack by the function it is corrupted. >The corrupted value is something very small (eg X.XXXXe-XXX) and varies >depending on the parameter. [rest of desription deleted] One possible source of problems is are you using prototypes and/or old style function declarations? If so, your floats are actually being passed as doubles which will mess things up. As an example: int foo(float, float, int); /* prototype */ int main() { float x,y; int i; ..... result = foo( x, y, i ); } int foo( x, y, i ) /* old stype declaration */ float x,y; /* floats are really double */ int i; { ... } If this is the case, either 1) use ANSI function declaration, or 2) change your prototype to double (If you generate prototypes using the /Zg option with MSC, the prototypes actually come out as being doubles!)
mmshah@athena.mit.edu (Milan M Shah) (11/01/90)
WRT float parameters getting corrupted. I ran into this problem once, and it is a known bug with MSC 5.1. I can't remember the exact details - I vaguely recall that it had something to do with either the float parameter being on an odd byte boundary, or being part of a struct that was more than 16 bytes long, or maybe both. I do, however, remember the workaround he suggested - pass a pointer to the float or struct instead. For exact details, call Microsoft. If this is too vague, I can probably dig up some code that shows where the problem occured and how it was 'fixed' Hope this helps. Milan .