The origin of sprintf-style string formatting

2019-06-23 02:38发布

The string formatting concept found in sprintf can be found in almost any language today (you know, smothering a string with %s %d %f etc. and providing a list of variables to fill their places).

Which langugage was it originally that had a library function or language construct which offered this functionality?

Please specify some kind of source reference to confirm your claim, so that we avoid pure speculation or guessing.

Regards

Robert

2条回答
Anthone
2楼-- · 2019-06-23 03:05

Wikipedia has a pretty thorough history. It suggests that the C printf function had its origins in BCPL's writef function.

查看更多
姐就是有狂的资本
3楼-- · 2019-06-23 03:16

I would say all of them trace their roots back to BCPL. We used BCPL to do operating systems programming for the 6809 processor two decades ago and it had a writef() function which took arguments such as %i2 (equivalent to C's %2d).

C was based on a cut-down version of BCPL and inherited a similar mechanism for formatting output and I'm pretty certain all other instances picked it up from C after that.

I could be wrong, it won't be the first or last time, but I'm pretty confident that's right, given what I know about the BCPL language and its origins.

查看更多
登录 后发表回答