April 03, 2002
"Walter" <walter@digitalmars.com> wrote in message news:a8dq8q$2di6$1@digitaldaemon.com...

> It works, but it's a lot of code generated <g>.

I don't see better idea...
Besides, printf()'s format string parsing is slow as well.


April 03, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:a8du0n$2fng$1@digitaldaemon.com...
> "Walter" <walter@digitalmars.com> wrote in message news:a8dq8q$2di6$1@digitaldaemon.com...
> > It works, but it's a lot of code generated <g>.
> I don't see better idea...
> Besides, printf()'s format string parsing is slow as well.

It's just awful hard to beat printf. I've also been known to printf out types as different types, for example, printing out floats with %x so I can check the bit pattern. Not quite as bad as vptr jamming, but ...

99% of the printf's I use are for debugging, and for that a quick and dirty printf works just great. I need to write a D version anyway so the format string can be a char[], and sprintf will write to a char[], etc. I'm really ready to abandon 0 terminated C strings!


April 03, 2002
"Walter" <walter@digitalmars.com> wrote in message news:a8ehr6$3i4$1@digitaldaemon.com...

> It's just awful hard to beat printf. I've also been known to printf out types as different types, for example, printing out floats with %x so I
can
> check the bit pattern. Not quite as bad as vptr jamming, but ...

That's why printf should still be there, whatever new output method is provided.

> 99% of the printf's I use are for debugging, and for that a quick and
dirty
> printf works just great.

Well maybe, but I was talking not only about screen output, but about generic IO as well: streams and such. Having text-based IO is especially convenient for socket streams, since most TCP/IP protocols are textual.

> I need to write a D version anyway so the format
> string can be a char[], and sprintf will write to a char[], etc. I'm
really

Your too fast, I've just started thinking of writing my own printf specially for D, with support for char[], imaginary and complex numbers etc... =)



April 03, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:a8evq4$5ul$1@digitaldaemon.com...
> "Walter" <walter@digitalmars.com> wrote in message news:a8ehr6$3i4$1@digitaldaemon.com...
>
<SNIP>
>
> > I need to write a D version anyway so the format
> > string can be a char[], and sprintf will write to a char[], etc. I'm
> really
>
> Your too fast, I've just started thinking of writing my own printf specially for D, with support for char[], imaginary and complex numbers etc... =)
>
>

Look who's talking!
:)


--
Stijn
OddesE_XYZ@hotmail.com
http://OddesE.cjb.net
_________________________________________________
Remove _XYZ from my address when replying by mail



April 09, 2002
"Walter" <walter@digitalmars.com> ha scritto nel messaggio news:a8ehr6$3i4$1@digitaldaemon.com...
>
>
> It's just awful hard to beat printf. I've also been known to printf out types as different types, for example, printing out floats with %x so I
can
> check the bit pattern. Not quite as bad as vptr jamming, but ...
>
> 99% of the printf's I use are for debugging, and for that a quick and
dirty
> printf works just great. I need to write a D version anyway so the format string can be a char[], and sprintf will write to a char[], etc. I'm
really
> ready to abandon 0 terminated C strings!

The real printf problems are:

 1. %s does not specify a size. This is due to the use of 0 terminated
strings,
     if you pass something non-0-terminated or something which is not a
string
     your program will probably crash (it usually happens on the customer's
     computer, not yours). If you remove 0-terminated strings, you remove
this
     problem.
 2. the size of the actual arguments passed are not known, and need not to
     match with format specifiers. I wonder what can happen if you specify a
     long int format and pass a plain int as actual argument.
 3. the user must remember all thoose little tricky letters ('d' for
integers, 'g'
     for floats, 'h' for shorts, who invented them?) to print simple types.

Once solved theese, I'm well with printf.

Ciao


April 09, 2002
Roberto Mariottini wrote:

>  2. the size of the actual arguments passed are not known, and need not to
>      match with format specifiers. I wonder what can happen if you specify a
>      long int format and pass a plain int as actual argument.

I don't know about all compilers (or what the C spec might be), but it seems in
my experiments that all ints are cast up to longs when passed to printf.  So if
you do this:
    char c;
    printf("%c\n",c);
c is actually cast to a long, passed that way, and then the printf code casts it
back to a char.  I don't know if they automatically get cast to signed or
unsigned.

--
The Villagers are Online! villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]


April 09, 2002
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CB317F9.3C763A11@deming-os.org...

> I don't know about all compilers (or what the C spec might be), but it
seems in
> my experiments that all ints are cast up to longs when passed to printf.
So if
> you do this:
>     char c;
>     printf("%c\n",c);
> c is actually cast to a long, passed that way, and then the printf code
casts it

But to remember that D long is not the C one...

If I recall it correctly, when you call the vararg function, the conversions are:

    (unsigned/signed) char, short -> int
    float -> double

> back to a char.  I don't know if they automatically get cast to signed or unsigned.

There's no sense in it, since both have the same bit pattern, so the PUSH instruction generated is absolutely the same.




April 09, 2002
Pavel Minayev wrote:

>     (unsigned/signed) char, short -> int
>     float -> double
>
> > back to a char.  I don't know if they automatically get cast to signed or unsigned.
>
> There's no sense in it, since both have the same bit pattern, so the PUSH instruction generated is absolutely the same.

The push is, but the cast is not.  If it's an unsigned, then you just add bytes of 0's...if it's signed, then you sign extend.

Anyhow, let's hope that Walter uses my typesafe varargs idea...or comes up with a better one :)

--
The Villagers are Online! villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]


April 09, 2002
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CB326F8.2D0A5A4D@deming-os.org...

> The push is, but the cast is not.  If it's an unsigned, then you just add
bytes
> of 0's...if it's signed, then you sign extend.

It's passed as is. Your responsibility is to supply the appropriate format specifier.

> Anyhow, let's hope that Walter uses my typesafe varargs idea...or comes up
with
> a better one :)

Oh yes. I'd even add it to the list of what has to be done for D to be
considered
beta (remember that one?).


1 2 3 4 5
Next ›   Last »