Closed p5pRT closed 21 years ago
I would expect the (s)printf formatters %lo\, %ld\, and %lx to be able to deal integers correctly for at least the values that are dealt with correctly by %o\, %d and %x.
Unfortunally\, that isn't true.
my $shift = 32; printf "%lo\, %o\n" => 1 \<\< $shift\, 1 \<\< $shift; printf "%ld\, %d\n" => 1 \<\< $shift\, 1 \<\< $shift; printf "%lx\, %x\n" => 1 \<\< $shift\, 1 \<\< $shift; __END__
This will print: 0\, 40000000000 0\, 4294967296 0\, 100000000
I expected: 40000000000\, 40000000000 4294967296\, 4294967296 100000000\, 100000000
Abigail
abigail@foad.org wrote: :I would expect the (s)printf formatters %lo\, %ld\, and %lx :to be able to deal integers correctly for at least the :values that are dealt with correctly by %o\, %d and %x.
Why? I think you're getting what you asked for - without 'l'\, you get an IV size\, which is 'long long' according to your configuration. With 'l'\, we cast to 'long' (4 bytes) which is correctly 0.
Are you saying we should define the 'l' modifier to be ignored if sizeof(IV) > sizeof(long)?
Hugo
On Fri\, Apr 12\, 2002 at 06:54:27PM +0100\, Hugo van der Sanden wrote:
abigail@foad.org wrote: :I would expect the (s)printf formatters %lo\, %ld\, and %lx :to be able to deal integers correctly for at least the :values that are dealt with correctly by %o\, %d and %x.
Why? I think you're getting what you asked for - without 'l'\, you get an IV size\, which is 'long long' according to your configuration. With 'l'\, we cast to 'long' (4 bytes) which is correctly 0.
Are you saying we should define the 'l' modifier to be ignored if sizeof(IV) > sizeof(long)?
Well\, according the documentation of sprintf\, the 'l' modifier interprets the integer as a 'long'. With no flags\, it should be treated as an 'int'.
And\, AFAIK\, sizeof(int) \<= sizeof(long). Now\, I'm not at all against %o/%d/%x to "do the right thing"\, but shouldn't %lo/%ld/%lx do the same thing?
I would not expect something to be truncated to a 'long' where it isn't truncated to an 'int'.
Perhaps all that's needed is a doc fix?
Abigail
On Fri\, Apr 12\, 2002 at 08:14:30PM +0200\, abigail@foad.org wrote:
On Fri\, Apr 12\, 2002 at 06:54:27PM +0100\, Hugo van der Sanden wrote:
abigail@foad.org wrote: :I would expect the (s)printf formatters %lo\, %ld\, and %lx :to be able to deal integers correctly for at least the :values that are dealt with correctly by %o\, %d and %x.
Why? I think you're getting what you asked for - without 'l'\, you get an IV size\, which is 'long long' according to your configuration. With 'l'\, we cast to 'long' (4 bytes) which is correctly 0.
Are you saying we should define the 'l' modifier to be ignored if sizeof(IV) > sizeof(long)?
Well\, according the documentation of sprintf\, the 'l' modifier interprets the integer as a 'long'. With no flags\, it should be treated as an 'int'.
Yes\, but here you are making the assumption that without the flags a [dox] is an "int". Even with 32-bit builds\, it isn't\, it's (usually) a "long". It's just a curse of (C's) history that "int" and "long" have been mistaken to be idnetical.
And\, AFAIK\, sizeof(int) \<= sizeof(long). Now\, I'm not at all against %o/%d/%x to "do the right thing"\, but shouldn't %lo/%ld/%lx do the same thing?
It probably should\, for consistency (with Perl\, if not C) -- but if so\, then the whole 'l' prefix becomes a complete no-op.
I would not expect something to be truncated to a 'long' where it isn't truncated to an 'int'.
Perhaps all that's needed is a doc fix?
Abigail
-- $jhi++; # http://www.iki.fi/jhi/ # There is this special biologist word we use for 'stable'. # It is 'dead'. -- Jack Cohen
On Fri\, Apr 12\, 2002 at 09:24:02PM +0300\, Jarkko Hietaniemi wrote:
On Fri\, Apr 12\, 2002 at 08:14:30PM +0200\, abigail@foad.org wrote:
On Fri\, Apr 12\, 2002 at 06:54:27PM +0100\, Hugo van der Sanden wrote:
abigail@foad.org wrote: :I would expect the (s)printf formatters %lo\, %ld\, and %lx :to be able to deal integers correctly for at least the :values that are dealt with correctly by %o\, %d and %x.
Why? I think you're getting what you asked for - without 'l'\, you get an IV size\, which is 'long long' according to your configuration. With 'l'\, we cast to 'long' (4 bytes) which is correctly 0.
Are you saying we should define the 'l' modifier to be ignored if sizeof(IV) > sizeof(long)?
Well\, according the documentation of sprintf\, the 'l' modifier interprets the integer as a 'long'. With no flags\, it should be treated as an 'int'.
Yes\, but here you are making the assumption that without the flags a [dox] is an "int". Even with 32-bit builds\, it isn't\, it's (usually) a "long". It's just a curse of (C's) history that "int" and "long" have been mistaken to be idnetical.
I'm not making any assumptions\, other than what the documentation promises me. (Yes\, after 2 decade in computing\, I'm still horribly naive!) It's the docs that say it shall be treated as a C 'int'.
Perhaps my bug report should have been that %[dox] isn't correctly truncating the values. ;-)
And\, AFAIK\, sizeof(int) \<= sizeof(long). Now\, I'm not at all against %o/%d/%x to "do the right thing"\, but shouldn't %lo/%ld/%lx do the same thing?
It probably should\, for consistency (with Perl\, if not C) -- but if so\, then the whole 'l' prefix becomes a complete no-op.
I don't think that's too bad; the current behaviour doesn't seen useful to me. I know the heritage\, and that's its coming from C\, where you do need the 'l' flag to prevent truncation to 'int'. Besides\, aren't the flags 'll'\, 'L' and 'q' already no-ops?
Abigail
Yes\, but here you are making the assumption that without the flags a [dox] is an "int". Even with 32-bit builds\, it isn't\, it's (usually) a "long". It's just a curse of (C's) history that "int" and "long" have been mistaken to be idnetical.
I'm not making any assumptions\, other than what the documentation promises me. (Yes\, after 2 decade in computing\, I'm still horribly naive!)
:-)
It's the docs that say it shall be treated as a C 'int'. Perhaps my bug report should have been that %[dox] isn't correctly truncating the values. ;-)
I'm afraid you'll soon find the 'h'...
And\, AFAIK\, sizeof(int) \<= sizeof(long). Now\, I'm not at all against %o/%d/%x to "do the right thing"\, but shouldn't %lo/%ld/%lx do the same thing?
It probably should\, for consistency (with Perl\, if not C) -- but if so\, then the whole 'l' prefix becomes a complete no-op.
I don't think that's too bad; the current behaviour doesn't seen useful to me. I know the heritage\, and that's its coming from C\, where you do need the 'l' flag to prevent truncation to 'int'. Besides\, aren't the flags 'll'\, 'L' and 'q' already no-ops?
Hmmm. They are no-ops in a different sense: the cause the format to be skipped completely (just as if you'd used\, say\, "%zz") if used with a non-quad-built Perl.
Abigail
-- $jhi++; # http://www.iki.fi/jhi/ # There is this special biologist word we use for 'stable'. # It is 'dead'. -- Jack Cohen
On Fri\, Apr 12\, 2002 at 09:53:53PM +0300\, Jarkko Hietaniemi wrote:
It's the docs that say it shall be treated as a C 'int'. Perhaps my bug report should have been that %[dox] isn't correctly truncating the values. ;-)
I'm afraid you'll soon find the 'h'...
AH\, but that does what I expect it to do from reading the documentation. ;-)
Not that I can remember ever having used 'h' (except when writing test cases for an implementation of sprintf I once wrote in LPC).
I don't think that's too bad; the current behaviour doesn't seen useful to me. I know the heritage\, and that's its coming from C\, where you do need the 'l' flag to prevent truncation to 'int'. Besides\, aren't the flags 'll'\, 'L' and 'q' already no-ops?
Hmmm. They are no-ops in a different sense: the cause the format to be skipped completely (just as if you'd used\, say\, "%zz") if used with a non-quad-built Perl.
Oh\, we could always make '%lo' skip the format if Perl ever gets compiled on a platform without longs. ;-)
Anyway\, it's weekend. Without email access. ;-)
Abigail
@abigail - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#8934 (status was 'resolved')
Searchable as RT8934$