D - printf()
- Andrew Edwards (8/8) Jul 05 2003 Should the following be legal?
- Walter (3/11) Jul 08 2003 Yes.
- Andrew Edwards (10/11) Jul 08 2003 The concern is that D allows us to compile and execute the program witho...
- Walter (5/13) Jul 08 2003 The compiler doesn't parse the printf format string any more than C does...
- Nic Tiger (12/28) Jul 08 2003 Intel C/C++ compiler DOES analyze string formats for ...printf family of
- Walter (3/8) Jul 08 2003 No, it's not that hard.
- Burton Radons (4/15) Jul 08 2003 Harder than safe varargs, and hackish - either you put in an ugly syntax...
- Walter (5/20) Jul 09 2003 something
- Matthew Wilson (9/25) Jul 08 2003 Intel C/C++ parses the printf()-famliy format strings, and I've been
Should the following be legal? ============== import stream; void main() { printf("%d + %d = %d"\n); // does not require stream import. stdout.printf("%d + %d = %d"\n); // requires stream import. }
Jul 05 2003
Yes. "Andrew Edwards" <edwardsac spamfreeusa.com> wrote in message news:be8bb6$9ra$1 digitaldaemon.com...Should the following be legal? ============== import stream; void main() { printf("%d + %d = %d"\n); // does not require stream import. stdout.printf("%d + %d = %d"\n); // requires stream import. }
Jul 08 2003
"Walter" <walter digitalmars.com> wrote in message news:bedtlp$2bi0$2 digitaldaemon.com...Yes.The concern is that D allows us to compile and execute the program without providing the variables to resolve the conversion specifiers; resulting in output of logical garbage. For example, compiling and executing the code as submitted earlier results in the following output: 1244984 + 4202759 = 1 4284568 + 1244984 = 4202759 Shouldn't the compiler prevent that?
Jul 08 2003
"Andrew Edwards" <edwardsac spamfreeusa.com> wrote in message news:beduip$2cho$1 digitaldaemon.com...The concern is that D allows us to compile and execute the program without providing the variables to resolve the conversion specifiers; resulting in output of logical garbage. For example, compiling and executing the code as submitted earlier results in the following output: 1244984 + 4202759 = 1 4284568 + 1244984 = 4202759 Shouldn't the compiler prevent that?The compiler doesn't parse the printf format string any more than C does. Right now, printf is just the C printf. There have been many proposals for a typesafe D printf, but there isn't an official one yet.
Jul 08 2003
Intel C/C++ compiler DOES analyze string formats for ...printf family of functions and issues warning if parameters doesn't coincide. Maybe for D it is not necessary (printf should be replaced with something better), but is it very difficult to provide this kind of check in DMC? Of course, check should be performed only for static format strings. Nic Tiger. "Walter" <walter digitalmars.com> wrote in message news:beeph4$4qh$2 digitaldaemon.com..."Andrew Edwards" <edwardsac spamfreeusa.com> wrote in message news:beduip$2cho$1 digitaldaemon.com...withoutThe concern is that D allows us to compile and execute the programinproviding the variables to resolve the conversion specifiers; resultingresultsoutput of logical garbage. For example, compiling and executing the code as submitted earlierain the following output: 1244984 + 4202759 = 1 4284568 + 1244984 = 4202759 Shouldn't the compiler prevent that?The compiler doesn't parse the printf format string any more than C does. Right now, printf is just the C printf. There have been many proposals fortypesafe D printf, but there isn't an official one yet.
Jul 08 2003
"Nic Tiger" <tiger7 progtech.ru> wrote in message news:bef1rr$dag$1 digitaldaemon.com...Intel C/C++ compiler DOES analyze string formats for ...printf family of functions and issues warning if parameters doesn't coincide. Maybe for D it is not necessary (printf should be replaced with something better), but is it very difficult to provide this kind of check in DMC? Of course, check should be performed only for static format strings.No, it's not that hard.
Jul 08 2003
Walter wrote:"Nic Tiger" <tiger7 progtech.ru> wrote in message news:bef1rr$dag$1 digitaldaemon.com...Harder than safe varargs, and hackish - either you put in an ugly syntax hinting about parameter usage (as GCC does) or you put in hardcoded identification. It's a dead end!Intel C/C++ compiler DOES analyze string formats for ...printf family of functions and issues warning if parameters doesn't coincide. Maybe for D it is not necessary (printf should be replaced with something better), but is it very difficult to provide this kind of check in DMC? Of course, check should be performed only for static format strings.No, it's not that hard.
Jul 08 2003
"Burton Radons" <loth users.sourceforge.net> wrote in message news:beftcl$182k$1 digitaldaemon.com...Walter wrote:something"Nic Tiger" <tiger7 progtech.ru> wrote in message news:bef1rr$dag$1 digitaldaemon.com...Intel C/C++ compiler DOES analyze string formats for ...printf family of functions and issues warning if parameters doesn't coincide. Maybe for D it is not necessary (printf should be replaced withOfbetter), but is it very difficult to provide this kind of check in DMC?I agree. That's why I never did it.Harder than safe varargs, and hackish - either you put in an ugly syntax hinting about parameter usage (as GCC does) or you put in hardcoded identification. It's a dead end!course, check should be performed only for static format strings.No, it's not that hard.
Jul 09 2003
Intel C/C++ parses the printf()-famliy format strings, and I've been (un)pleasantly surprised to see how many times code that was deemed good was found wanting. "Walter" <walter digitalmars.com> wrote in message news:beeph4$4qh$2 digitaldaemon.com..."Andrew Edwards" <edwardsac spamfreeusa.com> wrote in message news:beduip$2cho$1 digitaldaemon.com...withoutThe concern is that D allows us to compile and execute the programinproviding the variables to resolve the conversion specifiers; resultingresultsoutput of logical garbage. For example, compiling and executing the code as submitted earlierain the following output: 1244984 + 4202759 = 1 4284568 + 1244984 = 4202759 Shouldn't the compiler prevent that?The compiler doesn't parse the printf format string any more than C does. Right now, printf is just the C printf. There have been many proposals fortypesafe D printf, but there isn't an official one yet.
Jul 08 2003