Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"08-21-10 - autoprintf"

10 Comments -

1 – 10 of 10
Blogger Julien Koenen said...

Cool stuff, I'm looking forward to seeing the code.

August 21, 2010 at 6:18 PM

Blogger MH said...

Sweet. This looks great.

August 21, 2010 at 9:09 PM

Anonymous Anonymous said...

I realize you don't NEED %s, but does %s work or is it incompatible (since it can't tell the difference between a format string and an "argument" string)?

August 22, 2010 at 1:52 AM

Blogger jetro said...

What about order-independent arguments which are handy for L10n?

printf("%s said %s is cool", person1, person2);
might need order of person1 and person2 swapped for some other language.

So in such case it would be handy to have:
printf("%{2}s blabla %{1}s bla", person1, person2);

Apart from missing this, your autoprintf seems very cool! :-D

August 22, 2010 at 9:13 AM

Blogger cbloom said...

" I realize you don't NEED %s, but does %s work or is it incompatible (since it can't tell the difference between a format string and an "argument" string)? "

That mostly works out automatically. There are possible ambiguities, and what I do is look in the string for '%' , so there could be a problem if you are trying to pass a string literal with a % in it, and I treat it as a format string. eg. things like :

autoprintf("tricky %s","yes 100%",7);

August 22, 2010 at 11:31 AM

Comment deleted

This comment has been removed by the author.

August 22, 2010 at 2:50 PM

Blogger   said...

sounds good, lets see some code :)

August 22, 2010 at 2:56 PM

Blogger won3d said...

Random question: does this expand your code substantially?

August 22, 2010 at 8:33 PM

Blogger cbloom said...

I'll investigate that. It depends how much I make inline I guess.

BTW I'm gonna support arg reordering partly for that reason. Reordering would require me to generate a template function for each possible reorg, which is N! for N arguments. Way too much code. eg. something like :

U32 reorgCode = GetReorg(formatString);
switch(reorgCode) {
case 0: printf(a1,a2,a3);
case 1: printf(a1,a3,a2);
case 2: printf(a2,a1,a3);
...

no fun.

August 22, 2010 at 8:37 PM

Blogger cbloom said...

"I'm gonna support arg reordering "

->

"I'm *NOT* gonna support arg reordering"

August 22, 2010 at 8:51 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.