Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
July 06, 2003 printf() | ||||
---|---|---|---|---|
| ||||
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. } |
July 08, 2003 Re: printf() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Edwards | 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. > } > > |
July 08, 2003 Re: printf() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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? |
July 08, 2003 Re: printf() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Edwards | "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. |
July 08, 2003 Re: printf() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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... > > 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. > > |
July 09, 2003 Re: printf() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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... > > 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. > > |
July 09, 2003 Re: printf() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nic Tiger | "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. |
July 09, 2003 Re: printf() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> "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.
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!
|
July 09, 2003 Re: printf() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | "Burton Radons" <loth@users.sourceforge.net> wrote in message news:beftcl$182k$1@digitaldaemon.com... > Walter wrote: > > "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. > > 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! I agree. That's why I never did it. |
Copyright © 1999-2021 by the D Language Foundation