Quote:
Originally Posted by ******
Why is seconds not passed by reference, surely if you pass "3333" seconds you would want to know that that is 55 minutes and 33 seconds? And why do you return a string AND the values? A function should really only do one or the other - doing both is a waste of time if you only want one. Also:
pawn Код:
#define CT(%0) ((%0)==1)?(""):("s")) format(str, sizeof (str), "%d minute%s", d, CT(d));
Even if you do use the other method, there's no need for the # within the macro as the parameters are already strings. # is used to convert non-strings to strings, anything inside ""s are already strings.
|
Thanks for pointing out the seconds param not having a reference!
I guess you can call the seconds issue a sort of goof. It was removed when i was testing just so i could have a literal integer there instead (im lazy). The version that i actually use has it as a reference. I'll update the post i made, and actually fix that. I should've saw this when i was making an example for the thread, as i also used a literal integer there as well. Sorry for that, I'll fix it up (the entire post :P).
As for the macro, its just a reusable macro i made for things like format. I got sick of having to do:
Код:
format(String,sizeof(String), "There are %d %s left", Var, (Var == 1) ? ("second") : ("seconds"));
It wasn't made exactly for this function (im lazy, and like to shorten code with macro's ... even though macro's are tought to be the "devil" and should be avoided like the plague in other languages). I could very well use your macro, but i use my out of comfort really, nothing more (i've used it for so long im used to it :\). I know about the stringize operator (not as well as you, since you wrote the thing haha), the "#" is there for insurance, and wont actually affect speed in anyway since its not used at run-time.
The references are because not everyone wants a string with the time, some people may want to format it their own way, or save it (for some...odd reason. I would just save a unix timestamp, but w/e). I wanted it to fit everyone's needs.