Problem with sprintf and optimization?

Started by
6 comments, last by Ziggy5000 23 years, 9 months ago
Hi, got a little problem here... using sprintf as so: sprintf (lpVar,"%d",3); okay- here is the problem.... if compile with Visual Studio 6.0 under Win2000 -Optimize for maximum speed The resultant program goes into a 100% cpu loop and never returns -Optimize for default the resultant program seems to function okay. any Ideas? (got servicepack 3; gonna dl 4 tonight)
laxdigital.com
[email=ziggy@laxdigital.com]ziggy@laxdigital.com[/email]
Advertisement
Well... the problem is probably somewhere else.. Did you actually allocate memory for lpVar? And is it indeed a character pointer?
You better make sure that whatever is formatted into lpVar will be able to fit into lpVar. Know the format details of printf (). And be sure to allow room for the NULL terminator.

_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
okay, so here is what I did:

restored my source files to the original configuration-
(back''d up to CD-R)

recoded the changes I had made since last backup (not to many so no problem)

now it works?@!?@?@!?@???

I must have made a little mistake and not noticed? Weird....


In addition, when I ran WinDiff before I restored, the files that were different "looked" okay (code wise)....

can a workspace corrupt?

Jason
laxdigital.com
[email=ziggy@laxdigital.com]ziggy@laxdigital.com[/email]
In Windows, just about everything can corrupt.
quote:Original post by Anonymous Poster

In Windows, just about everything can corrupt.


AMEN!!!!!!!! Use BeOS.


B e S


It's Da BOMB Baby!!!
BeSIt's Da BOMB Baby!!!. o O ~ A little nonsense now and then,is relished by the wisest men~ O o .-- Willy Wonka
Seriously, you must''ve mis-allocated something along the way is all I can see. Forgot to reference the memory location correctly I''d assume. The default optimization was just a bit more forgiving.


BeS
It's Da BOMB Baby!!!
BeSIt's Da BOMB Baby!!!. o O ~ A little nonsense now and then,is relished by the wisest men~ O o .-- Willy Wonka
Wrenhal''s right. If you ever get a "works in release but not in debug" or "works in optimization but not with no-opt", your bug is insidious--either a wild pointer or (if multithreading) a race condition between threads. The key is
1) prevention: don''t leave yourself the opportunity to make mistakes. adopt good (& SAFE) programming styles.
2) debug skills: when "it" breaks, you need to have the ability to figure out exactly what broke. This is one of the most essential software development skills that nobody really "teaches" in a classroom.

This topic is closed to new replies.

Advertisement