From: Bjorn R. <br...@ma...> - 2004-08-21 16:08:48
|
On Fri, 2004-08-20 at 20:45, Jan Engelhardt wrote: > Other printf() might not recognize that then. > (Even though I only know of Glibc supporting gaps) A portable solution is not possible, as UNIX98 says that gaps results in undefined behavior. In practice this typically means that implementations do not have to handle this situation, and can crash or delete random files, and still be standard compliant. I feel very uncomfortable about emulating glibc behavior for the sake of compatibility. I had a quick look at the glibc printf implementation, and its behavior in this situation seems arbitrary. I found the following comment in the code: /* XXX Could do sanity check here: If any element in ARGS_TYPE is still zero after this loop, format is invalid. For now we simply use 0 as the value. */ To understand this comment you should know that (1) if an element in args_type is zero, then there is a gap, and (2) "use 0" means that the argument in the gap will coincidentially be regarded as an int. Anyways, the comment suggests that glibc may change its behavior in the future. > How about this: > If there is no ignore specifier in the format string, assume gaps are > sizeof(int), otherwise use the specified widths in the format. This is indirect way of saying that you will not use the ignore modifier if we implemented it ;) I will need to give this suggestion more thought. > Can't we assume the user knows what he's doing, in this case? In this situation the user can be a non-developer (typically a writer who is translating the application into another human language.) I will rather have trio return an error, than to limp along with potential side-effects (who knows what security violations that could result in.) Having said that, however, I am open to allowing multiple references to the same argument if they have the same type. |