C++ sprintf from unknown argument
Try to write a nodejs sprintf native implementation while improving my c++ skills, i've reseach on how to provide unknown lenghth of arguments to sprintf. I first though i could use vsprintf but couldn't find how to populate it. basically, the nodejs/v8 binding give me an argument array which i could convert to a vector or sommething else, but don't know how to convert it to va_list expected by vsprintf or any other alternative that could make it work.
开发者_运维知识库Does any one could propose me a strategy?
Generally it's compiler and platform dependant. You can look at the implementation of va_start
and va_arg
etc for your compiler of choice, and push the data in the correct manner into the stack using the asm
directive.
I wouldn't do that though, if it's critical for your implementation to imitate sprintf
- loop on the parameters and process them one at a time concatenating results, that would be much more robust and portable.
精彩评论