compiled size savings, printf vs string concat

Hi everyone.

First post and totally new to arduino, in fact I don't even have the board yet but I have started coding a bit. I'm new to C++ too and am after some advice. Can anyone tell me the difference between

String dateTime = printf("%s/%s/%s %s:%s:%s", dayOfMonth, month, year, hour, minute, second);

And

String dateTime = (String)dayOfMonth + "/" + (String)month + "/" + (String)year + " " + (String)hour + ":" + (String)minute + ":" + (String)second;

Other than printf seems to increase the compiled size by about 750 precious bytes. Whereas in other places using print is saving me on the compiled size.

Thanks in advance for any info :slight_smile:

I'm not even sure what printf does on an Arduino (no stdout), and the normal printf returns the length of the string it prints, so I'm not clear what you're trying to achieve.

i seem to have my printf and sprintf mixed up. so yes printf prprobably wouldn't do much on and arduino. i will recompile with sprintf later and se if there is still such a big difference.

sprintf also only returns the length of the converted string, so you need to rearrange your sketch.
Since both printf and sprintf individually do very little (the work is done in vfprint), I don't expect much of a saving.

watch out, on AVRs, you might get bugs if you have too many arguments in an argument list

AWOL:
sprintf also only returns the length of the converted string, so you need to rearrange your sketch.
Since both printf and sprintf individually do very little (the work is done in vfprint), I don't expect much of a saving.

oh i see what you mean, so how come the compiler dosent moan about trying to put an int iinto a string type?

frank26080115:
watch out, on AVRs, you might get bugs if you have too many arguments in an argument list

oh-er any guidelines on how many is too many?

so how come the compiler dosent moan about trying to put an int iinto a string type?

I don't know - I'd have to look at the overloaded assignment operator for String.
I don't use String at all.
Maybe it gives a (suppressed) warning.