Click here to Skip to main content
15,915,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Reading from a file Pin
Rajesh R Subramanian30-Jun-10 1:26
professionalRajesh R Subramanian30-Jun-10 1:26 
QuestionOptimisation challenge... Pin
MarkB77730-Jun-10 0:00
MarkB77730-Jun-10 0:00 
AnswerRe: Optimisation challenge... Pin
Aescleal30-Jun-10 0:24
Aescleal30-Jun-10 0:24 
GeneralRe: Optimisation challenge... Pin
KarstenK30-Jun-10 3:48
mveKarstenK30-Jun-10 3:48 
GeneralRe: Optimisation challenge... Pin
Aescleal30-Jun-10 4:14
Aescleal30-Jun-10 4:14 
GeneralRe: Optimisation challenge... Pin
KarstenK30-Jun-10 4:38
mveKarstenK30-Jun-10 4:38 
GeneralRe: Optimisation challenge... Pin
MarkB77730-Jun-10 10:52
MarkB77730-Jun-10 10:52 
GeneralRe: Optimisation challenge... Pin
Aescleal30-Jun-10 11:17
Aescleal30-Jun-10 11:17 
It was the inline that made me think it was a C++ compiler - I'm not up on C99 (which presumably added it) so sorry about any confusion.

While sprintf is a bit cleaner one thing to watch out for is the size of the code you get linked in when you use sprintf. It's a bit of a monster function so if it's not already linked in the code base you might be better off using strcpy/memcpy [1] to save space. If you're in a corner try both versions and see which is smaller.

Another slight problem with sprintf is that the function has got to parse the format string before it can actually copy anything which usually makes:

sprintf( buff, "%s%s" );


a pretty slow way of doing strcpy and strcat.

One final point (and if you're maintaining a code base it's not something you can change easily to) is to use length prepended strings instead of zero terminated ones. As one of the other posters (Chris L IIRC) pointed out if you know the size of the strings you can use memcpy instead of strcpy. Prepending the size saves you the balls ache of calling strcpy everywhere at the cost of a bit more arithmetic to maintain the length.

Cheers,

Ash

[1] Just about every compiler I've used since 1991 has inlined calls to strcpy and memcpy as it eliminates the function call overhead which is faster and saves space. I've never seen an inlined sprintf implementation in C though.
AnswerRe: Optimisation challenge... Pin
KarstenK30-Jun-10 3:50
mveKarstenK30-Jun-10 3:50 
AnswerRe: Optimisation challenge... [modified] Pin
Chris Losinger30-Jun-10 4:19
professionalChris Losinger30-Jun-10 4:19 
GeneralRe: Optimisation challenge... Pin
MarkB77730-Jun-10 11:01
MarkB77730-Jun-10 11:01 
GeneralRe: Optimisation challenge... Pin
Chris Losinger30-Jun-10 11:41
professionalChris Losinger30-Jun-10 11:41 
GeneralRe: Optimisation challenge... Pin
MarkB77730-Jun-10 12:00
MarkB77730-Jun-10 12:00 
QuestionWin32_ScheduledJob Pin
Jayapal Chandran29-Jun-10 23:36
Jayapal Chandran29-Jun-10 23:36 
Questionscollbar in CStatic Pin
kk.tvm29-Jun-10 23:28
kk.tvm29-Jun-10 23:28 
AnswerRe: scollbar in CStatic Pin
Cedric Moonen29-Jun-10 23:37
Cedric Moonen29-Jun-10 23:37 
GeneralRe: scollbar in CStatic Pin
kk.tvm29-Jun-10 23:57
kk.tvm29-Jun-10 23:57 
GeneralRe: scollbar in CStatic Pin
Cedric Moonen30-Jun-10 0:13
Cedric Moonen30-Jun-10 0:13 
GeneralRe: scollbar in CStatic Pin
kk.tvm30-Jun-10 0:39
kk.tvm30-Jun-10 0:39 
GeneralRe: scollbar in CStatic Pin
Cedric Moonen30-Jun-10 1:06
Cedric Moonen30-Jun-10 1:06 
GeneralRe: scollbar in CStatic Pin
kk.tvm30-Jun-10 1:21
kk.tvm30-Jun-10 1:21 
QuestionMessage Removed Pin
29-Jun-10 22:34
learningvisualc29-Jun-10 22:34 
AnswerRe: Detecting sim card reader Pin
LloydA11130-Jun-10 1:16
LloydA11130-Jun-10 1:16 
Questionconditional menu Pin
josip cagalj29-Jun-10 22:27
josip cagalj29-Jun-10 22:27 
AnswerRe: conditional menu Pin
Richard MacCutchan30-Jun-10 1:34
mveRichard MacCutchan30-Jun-10 1:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.