RE: sprintf weirdness
"Andras Balogh" <[email protected]>
| Newsgroups | gmane.games.devel.windows |
|---|---|
| Message-ID | <[email protected]> |
> (1) Could it be that "buf" is somehow corrupted before you check its
> contents? Maybe try the following:
>
> sprintf( buf, "Hey!-->%.3f<--Look!", 0.05f );
>
> (making sure "buf" can handle the extra text) and see that the
> stuff before and after the floating-point field appears in "buf"
> as expected.
Tried that, and it's not corrupted (I can see the "Hey" "Look!" messages in
buf, but it's still "0." In the middle).
> (2) Try out the following code from MSDN -- perhaps changing "_fcvt"
> to "_cfltcvt" as a wild guess if it fails to link with your crt0.
> Maybe testing cases similar to your 0.05f case with this function
> in particular will narrow down the problem.
>
> /* FCVT.C: This program converts the constant
> * 3.1415926535 to a string and sets the pointer
> * *buffer to point to that string.
> */
>
> #include <stdlib.h>
> #include <stdio.h>
>
> void main( void )
> {
> int decimal, sign;
> char *buffer;
> double source = 3.1415926535;
>
> buffer = _fcvt( source, 7, &decimal, &sign );
> printf( "source: %2.10f buffer: '%s' decimal: %d sign: %d\n",
> source, buffer, decimal, sign );
> }
>
> // Output
> // source: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0
_fcvt seems to work fine! Strange! So what does that mean?
> (3) Maybe put a memory breakpoint on "buf" to see when and how it is
> modified. Perhaps you'll find some unexpected modifications
> shortly AFTER your sprintf() call, and BEFORE your examination
> of the result.
Actually, I did step through printf, until the call of that _cfltcvt, when
the result immediately appeared in the buffer, so the only thing that could
screw up is _cfltcvt...
> (4) Finally, I don't want to raise any undue panic, but you might
> be having psychotic hallucinations. It goes without saying that
> you are using your own crt0 on the advice of the voices in your head,
> but the question is whether or not your paranoia has you believing
> that space aliens tampered with your private crt0 to keep you
> from learning more than "0." -- after all, knowing the full
> value, 0.050, would expose the horrifying conspiracy. For sure
> the sys admins of your region of the Matrix would have to change
> some parameters to restore balanced gameplay.
I have hallucinations all the time! I feel dizzy, and my eyes project words
into my brain written by some guy called Colin.. but I don't think he really
exists. I think he's just a helper bot installed into our brains (hmm, maybe
he's responsible for my recent memory leaks? I really need a decent garbage
collector!). Anyway, I don't fear the aliens, and I won't let them mess with
my crt0!!
Cheers,
Andras
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555