Talk:Printf
C/C++ Unassessed | ||||||||||
|
Old VfD discussion
from VfD:
Wikipedia is not a manual. (And if it were, it certainly wouldn't be a C manual) --fvw* 21:42, 2004 Nov 27 (UTC)
- Keep - I think an entry on printf in general should exist, but it shouldn't be particularly language specific or implementation-centric. In short, it should be more of an overview of the concept of printf, not it's specific use and features. Should be a cleanup Zachlipton 22:27, 27 Nov 2004 (UTC)
- Move to Wikibooks for C language. Exactly the place. Mikkalai 22:49, 27 Nov 2004 (UTC)
- Good thinking. I would say to move it there and then use the Wikipedia entry for a more general look at printf. Zachlipton 23:08, 27 Nov 2004 (UTC)
- Delete. Wikipedia is not your local manpages. Anyone needing this already has the documentation. There really isn't much, conceptually, behind printf() that isn't language specific. --Improv 23:21, 27 Nov 2004 (UTC)
- I think there is something to printf (maybe not a lot, but certainly something) that is the concept of the function and not related to the implementation. I'll try to mock up a better version of this entry on it's talk page when I get a chance. Zachlipton 01:54, 28 Nov 2004 (UTC)
- I disagree, but let me know when you make said mockup -- I am willing to listen to arguments otherwise. --Improv 05:27, 1 Dec 2004 (UTC)
- Definitely there is something --- look how hard it is to implement printf as a function, or even as a hard-coded language mechanism in a strongly statically typed language (such as, e.g., Objective Caml). This is not yet another standard library function... --Mikon 20:22, 16 December 2006 (UTC)
- I think there is something to printf (maybe not a lot, but certainly something) that is the concept of the function and not related to the implementation. I'll try to mock up a better version of this entry on it's talk page when I get a chance. Zachlipton 01:54, 28 Nov 2004 (UTC)
- Keep - agree with Zach. But add C-specific stuff to Wikibooks. --Whosyourjudas (talk) 01:19, 28 Nov 2004 (UTC)
- Delete, basic example of "Wikipedia is not a manual" Gazpacho 01:52, 28 Nov 2004 (UTC)
- Delete: As others have said: no man pages. Geogre 01:57, 28 Nov 2004 (UTC)
- Keep. More likely than other functions to up in everyday conversation. - RedWordSmith 03:41, Nov 28, 2004 (UTC)
- This is an exception to the rule. Keep and cleanup. Agree with Zachlipton. —[[User:Radman1|RaD Man (talk)]] 03:45, 28 Nov 2004 (UTC)
- Delete: DCEdwards1966 05:16, Nov 28, 2004 (UTC)
- Cleanup as suggested by Zachlipton. Printf-like functions are common enough that an article on the basic theory has merit beyond the 'man page' level. -- Antaeus Feldspar 05:31, 28 Nov 2004 (UTC)
- Keep. Most notable of all C functions. It would be hard to read other articles about C unless there is a description of printf available one wikilink away. jni 11:57, 28 Nov 2004 (UTC)
- Keep - that's a classic. Although I think the article doesn't need all these switches. Grue 18:31, 28 Nov 2004 (UTC)
- Keep. It's famous enough unlike sscanf. This is one of the few exceptions to the rule. Jeltz 20:48, 2004 Nov 28 (UTC)
- Forgot to add that if it should be kept the man stuff obviously has to go to wikibooks. But there si potential for having a dictionary article about printf or to make it a redirect to a page about printfunctions in general. Jeltz 20:52, 2004 Nov 28 (UTC)
- Keep. Notable function. ElBenevolente 00:19, 29 Nov 2004 (UTC)
- Keep, printf isn't just any function, it's the function. Like others have said, it's the exception to the rule, and thoroughly necessary to discussions of C related topics. Shane King 23:26, Nov 30, 2004 (UTC)
A quick update: I went ahead and put the C-specific bits into Wikibooks (there has not been very much progress on the C wikibook, but I made space and included it). I'll try to rewrite the existing Wikipedia entry when I have the time. If someone else wants to do it, of course go right on ahead. Zachlipton 01:40, 29 Nov 2004 (UTC)
- Strong keep. Notable function. Certainly should have the options included with it. --Idont Havaname 06:24, 29 Nov 2004 (UTC)
- keep and note that printf is used in other languages too. Possibly remove the list of format specifications and link to it elsewhere (wikibooks or other sources). ~leif ☺ HELO 06:44, 29 Nov 2004 (UTC)
- Keep, notable. [[User:GRider|GRider\talk]] 19:45, 29 Nov 2004 (UTC)
- Rename, a page for printf doesn't really have a place here - however, the concept of formatted output is one that many languages have in common - as is actually mentioned by the article. I suggest renaming this whole topic to Formatted output or some similar name and removing all the discussion on printf-specific format flags instead showing a few different ways of specifying flags - like Common Lisp's tilde-character vs C's percent-width-flags. A link to the specification of printf (such as the SUSv3 link at the bottom) should be sufficient coverage of printf's C API. The article should further be divided into sections and needs some general cleanup. olsner 08:39, 14 January 2007 (UTC)
end moved discussion
Unattributed edits
The edits by User:68.100.130.21 on this page were by me. --Graue 21:31, 11 October 2005 (UTC)
v variants
the v-variants need to be explained better. Why are they necessary? I can understand that this has to do with the fact that you cannot simply
char* f(char* s, ...){ printf(s, ...); // what should the arguments be??? }
but a code example for how vprintf solves that would be nice. --MarSch 13:33, 13 April 2006 (UTC)
Error in sprintf example
In the sprintf example, related to buffer overflows, it says: "If username in the above example exceeds 50 characters in length..." Having 35 characters on username will be enough to overflow the buffer. They forgot to count the characters in "Your name is ", period, newline and terminating null character.
Implimentation of printf
I think it would be very helpful to have an implimentation of printf - how it works at a lower level. I would think that it uses write() at the most basic portable level, but I have no idea where to find if thats true, or how it works. Fresheneesz 22:07, 17 September 2006 (UTC)
According to the spec, printf places its output on the stdout stream (which is a global variable of type FILE*) which is usable with eg fputc, fputs or fwrite. So somewhere along the line, printf must use one of those functions. Here's a link to glibc's implementation of vfprintf (in glibc, vfprintf is called by printf to do the actual work). It's not pretty! olsner 08:39, 14 January 2007 (UTC)
Could some one translate russian article? —The preceding unsigned comment was added by 89.223.67.131 (talk) 14:00, 14 January 2007 (UTC).
'*' width identifier (pad to width given in argument)
The current explanation is confusing although strictly speaking correct. The statement that the value n is the next argument means that n should be the next argument that printf will parse from its argument list. Because printf at the point when it reads the '*' has not read the data value yet; this means that the width argument should come before the associated data value. Thus, the example is correct. I can't figure out how to re-word this so that it will be clear immediately clear even if the reader doesn't understand how printf works internally. --24.226.31.7 05:08, 8 February 2007 (UTC)
- I've rewritten the explanations of "*". See if it works any better. --Deryck C. 02:53, 10 February 2007 (UTC)
Typo
echo -n -e "$FOO\t$BAR'
Are the quotations right? I don't think so, but I do not know whether " or ' is correct in Shebang (Unix)? --Lazer erazer 19:31, 10 April 2007 (UTC)
- They weren't right; and they should've been
"
in order to have the$
character assume the appropriate semantics (using'
would've protected the$
from shell interpretation). I fixed. --tiny plastic Grey Knight ⊖ 13:18, 2 August 2007 (UTC)
history
How about some history here? I failed to learn the thing I wanted to learn when I came to read this article: Where did the name "printf" come from? What's the 'f' for? Why isn't it simply named "print"? I remember being originally told that the 'f' stood for 'function', because it was the print function, but that makes little sense since *every* library call in C is a function. It wasn't fopenf() or strcpyf() or mallocf(). So what's the origin of the 'f'?
- As far as I'm aware it means "print formatted text". I don't have a source for that, though. --tiny plastic Grey Knight ⊖ 11:40, 2 August 2007 (UTC)
%q
Lua has a %q
specifier in its string.format()
function (which is basically just like PHP's sprintf()
) which accepts a string argument and prints it with all special characters (like quotes, for instance) escaped with backslashes (no quote delimiters are placed on the result unless you include them in the format string yourself). Does this variant exist in any other languages? Is it worth mentioning? --tiny plastic Grey Knight ⊖ 11:40, 2 August 2007 (UTC)
rewrites
I made a new, smaller, tidier lead paragraph, and moved the old one down into a "printf in different languages" section. That bit reads a bit oddly now that it's a section, but then again a lot of the article wouldn't suffer from a rewrite. I think a slightly more language-agnostic approach would be nice, with any particularly notable language idiosyncracies collected into a section lower down. --tiny plastic Grey Knight ⊖ 13:11, 2 August 2007 (UTC)
printf
in Java
The reason that I said that Java's implementation of printf
gives it the functionality of both printf
and fprintf it that it is possible to open a PrintStream object to write to a file and call that object's printf
method to write to that file (similar in practice to fprintf
, but more syntactically similar to printf
). Because System.err
and (obviously) System.out
are both PrintStream
objects, they both support printf
. --Btx40 (talk) 21:07, 28 April 2008 (UTC)
Should it not be mentioned that Java 1.5 and later also support a form of sprintf
in the form of String.format
method. It does differ in name, but the application of the function is nearly identical. --Zanthra (talk) 07:20, 20 May 2008 (UTC)
- It has aleady been mentioned. I'm not sure if the Java implementation is the only ont to throw exception on an error condition. (There is the .NET impementation, but that uses a substantially different syntax) --Btx40 (talk) 18:58, 21 May 2008 (UTC)
- Actually, I added the mention of it shortly after posting in this. --64.175.43.196 (talk) 22:29, 21 May 2008 (UTC)
Precision
The section on precision uses "*" in the beginning of the sentence, shouldn't it be ".*" instead? The flag ".*" is used in the example printf
statement in the second sentence. 64.94.55.231 (talk) 18:02, 16 June 2008 (UTC)