Thread overview
printf()
Jul 06, 2003
Andrew Edwards
Jul 08, 2003
Walter
Jul 08, 2003
Andrew Edwards
Jul 08, 2003
Walter
Jul 08, 2003
Nic Tiger
Jul 09, 2003
Walter
Jul 09, 2003
Burton Radons
Jul 09, 2003
Walter
Jul 09, 2003
Matthew Wilson
July 06, 2003
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
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
"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
"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
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
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
"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
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
"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.