|
-
Dec 4th, 2001, 11:05 PM
#1
Thread Starter
transcendental analytic
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 5th, 2001, 01:32 PM
#2
Ked gave you ecvt()
It actually does something like this:
Code:
char t[20];
double z=10;
sprintf(t,"%f",z);
-
Dec 5th, 2001, 01:46 PM
#3
Thread Starter
transcendental analytic
Jim, whats so cool about using sprintf, it has to interpret the "%f" at runtime right?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 5th, 2001, 02:04 PM
#4
No. the compiler takes all of the stuff that is pre-defined like %f and provides a vector directly to the conversion routine. If the string is _T or WCHAR then it gets even messier and uses another routine.
If you play around like this: "%5.2f", then the code doesn't go directly to conversion at runtime. You can look at the asm c++ generates and see this. Change the compile options to produce an asm list.
Any numeric -> string conversion involves a fair amount of overhead. Formatting in general is very expensive. You can look at this as just formatting with type conversion.
-
Dec 5th, 2001, 02:28 PM
#5
Thread Starter
transcendental analytic
Code:
; 138 : char t[20];
; 139 : double z=10;
; 140 : sprintf(t,"%f",z);
lea eax, DWORD PTR _t$[esp+20]
push 1076101120 ; 40240000H
push 0
push OFFSET FLAT:??_C@_02JBAA@?$CFf?$AA@ ; `string'
push eax
call _sprintf
add esp, 16 ; 00000010H
Not that i understand why the parameters but _sprintf gets called and only other reference in the listing is
EXTRN _sprintf:NEAR
same thing here:
Code:
; 138 : char t[20];
; 139 : double z=10;
; 140 : sprintf(t,"%5.2f",z);
lea eax, DWORD PTR _t$[esp+20]
push 1076101120 ; 40240000H
push 0
push OFFSET FLAT:??_C@_05MPII@?$CF5?42f?$AA@ ; `string'
push eax
call _sprintf
add esp, 16 ; 00000010H
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 5th, 2001, 03:00 PM
#6
That's interesting. The last time I tried this , there were big differences in the entry point call. I wonder why. Sorry.
I don't have an answer, unless the compiler or the _sprintf entry point have changed since I last played with it.
We were testing performance and found the "%5.2f" was slower than "%f" for several hundred thousand iterations. So, we looked at the asm, and there was a load of difference. We were converting hundreds of millions of IBM BCD's to doubles, doing some calculations, then to strings and inserting them into a DB. The strings had to be a fixed format.
-
Dec 5th, 2001, 03:05 PM
#7
Thread Starter
transcendental analytic
Well, i suppose you won't need that parameter 
Code:
; 138 : char t[20];
; 139 : sprintf(t,"%5.2f");
lea eax, DWORD PTR _t$[esp+20]
push OFFSET FLAT:??_C@_05MPII@?$CF5?42f?$AA@ ; `string'
push eax
call _sprintf
add esp, 8
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|