February 15, 2011 Re: Integer conversions too pedantic in 64-bit | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Piotr Szturmaj | On 02/15/2011 03:44 AM, Piotr Szturmaj wrote: > spir wrote: >> Rename size-t, or rather introduce a meaningful standard alias? (would >> vote for Natural) > > Maybe ptrint and ptruint? If ptr means pointer, then it's wrong: size-t is used for more than that, I guess. Strangely enough, while "size" may suggest it, .length does not return a size_t but an uint. Denis -- _________________ vita es estrany spir.wikidot.com | |||
February 15, 2011 Re: Integer conversions too pedantic in 64-bit | ||||
|---|---|---|---|---|
| ||||
Posted in reply to spir | Am 15.02.2011 12:50, schrieb spir:
> On 02/15/2011 03:44 AM, Piotr Szturmaj wrote:
>> spir wrote:
>>> Rename size-t, or rather introduce a meaningful standard alias? (would
>>> vote for Natural)
>>
>> Maybe ptrint and ptruint?
>
> If ptr means pointer, then it's wrong: size-t is used for more than
> that, I guess. Strangely enough, while "size" may suggest it, .length
> does not return a size_t but an uint.
>
> Denis
.length of what? An array?
I'm pretty sure it returns size_t.
Cheers,
- Daniel
| |||
February 15, 2011 Re: Integer conversions too pedantic in 64-bit | ||||
|---|---|---|---|---|
| ||||
Posted in reply to spir | spir wrote:
> On 02/15/2011 03:44 AM, Piotr Szturmaj wrote:
>> spir wrote:
>>> Rename size-t, or rather introduce a meaningful standard alias? (would
>>> vote for Natural)
>>
>> Maybe ptrint and ptruint?
>
> If ptr means pointer, then it's wrong: size-t is used for more than
> that, I guess. Strangely enough, while "size" may suggest it, .length
> does not return a size_t but an uint.
ptr prefix shows that int/uint depends on CPU word (32/64 bit), i.e. they have the same size as pointer. However, it may led to confusion, which type - signed or unsigned - is right for the job.
| |||
February 15, 2011 Re: Integer conversions too pedantic in 64-bit | ||||
|---|---|---|---|---|
| ||||
Posted in reply to spir | Am 15.02.2011 11:30, schrieb spir:
> On 02/15/2011 02:58 AM, Nick Sabalausky wrote:
>> "Jonathan M Davis"<jmdavisProg@gmx.com> wrote in message
>> news:mailman.1650.1297733226.4748.digitalmars-d@puremagic.com...
>>> On Monday, February 14, 2011 17:06:43 spir wrote:
>>>>
>>>> Rename size-t, or rather introduce a meaningful standard alias? (would
>>>> vote
>>>> for Natural)
>>>
>>> Why? size_t is what's used in C++. It's well known and what lots of
>>> programmers
>>> would expect What would you gain by renaming it?
>>>
>>
>> Although I fully realize how much this sounds like making a big deal
>> out of
>> nothing, to me, using "size_t" has always felt really clumsy and
>> awkward. I
>> think it's partly because of using an underscore in such an otherwise
>> short
>> identifier, and partly because I've been aware of size_t for years and
>> still
>> don't have the slightest clue WTF that "t" means. Something like
>> "wordsize"
>> would make a lot more sense and frankly feel much nicer.
>>
>> And, of course, there's a lot of well-known things in C++ that D
>> deliberately destroys. D is a different language, it may as well do
>> things
>> better.
>
> Agreed. While making something different...
> About the suffix "-_t", I bet it means type, what do you think? (may
> well be wrong, just because I have here and there seen custom types like
> name_t or point_t or such) Anyone has a history of C/++ at hand?
>
> Denis
I've seen _t in C code for typedef'ed types.
like
struct foo_s { ... };
typedef struct foo_s foo_t;
and then "foo_t myfoo; myfoo.x = 42;" etc
instead of "struct foo_s myfoo; myfoo.x = 42;" etc
and also stuff like
typedef float vec_t;
typedef vec_t vec3_t[3];
So it is used to indicate that the it's an aliased type.
I don't see the problem with size_t.
It's the type used for sizes. sizeof(foo) (or foo.sizeof in D) uses it.
Cheers,
- Daniel
| |||
February 15, 2011 Re: Integer conversions too pedantic in 64-bit | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Mon, 14 Feb 2011 20:58:17 -0500, Nick Sabalausky <a@a.a> wrote:
> "Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message
> news:mailman.1650.1297733226.4748.digitalmars-d@puremagic.com...
>> On Monday, February 14, 2011 17:06:43 spir wrote:
>>>
>>> Rename size-t, or rather introduce a meaningful standard alias? (would
>>> vote
>>> for Natural)
>>
>> Why? size_t is what's used in C++. It's well known and what lots of
>> programmers
>> would expect What would you gain by renaming it?
>>
>
> Although I fully realize how much this sounds like making a big deal out of
> nothing, to me, using "size_t" has always felt really clumsy and awkward. I
> think it's partly because of using an underscore in such an otherwise short
> identifier, and partly because I've been aware of size_t for years and still
> don't have the slightest clue WTF that "t" means. Something like "wordsize"
> would make a lot more sense and frankly feel much nicer.
>
> And, of course, there's a lot of well-known things in C++ that D
> deliberately destroys. D is a different language, it may as well do things
> better.
Hey, bikeshedders, I found this cool easter-egg feature in D! It's called alias! Don't like the name of something? Well you can change it!
alias size_t wordsize;
Now, you can use wordsize instead of size_t in your code, and the compiler doesn't care! (in fact, that's all size_t is anyways *hint hint*)
;)
-Steve
| |||
February 15, 2011 Re: Integer conversions too pedantic in 64-bit | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Sometimes I think we should troll the users a little and make a release with names like so: alias size_t TypeUsedForArraySizes_Indexes_AndOtherRelatedTasksThatNeedAnUnsignedMachineSizeWord; alias ptrdiff_t TypeUsedForDifferencesBetweenPointers_ThatIs_ASignedMachineSizeWordAlsoUsableForOffsets; alias iota lazyRangeThatGoesFromStartToFinishByTheGivenStepAmount; Cash money says everyone would be demanding an emergency release with shorter names. We'd argue for months about it... and probably settle back where we started. | |||
February 15, 2011 Re: Integer conversions too pedantic in 64-bit | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Daniel Gibson | On 02/15/2011 02:01 PM, Daniel Gibson wrote: > Am 15.02.2011 12:50, schrieb spir: >> On 02/15/2011 03:44 AM, Piotr Szturmaj wrote: >>> spir wrote: >>>> Rename size-t, or rather introduce a meaningful standard alias? (would >>>> vote for Natural) >>> >>> Maybe ptrint and ptruint? >> >> If ptr means pointer, then it's wrong: size-t is used for more than >> that, I guess. Strangely enough, while "size" may suggest it, .length >> does not return a size_t but an uint. >> >> Denis > > .length of what? An array? > I'm pretty sure it returns size_t. unittest { int[] ints; auto l = ints.length; writeln(typeof(l).stringof); } press play ;-) denis -- _________________ vita es estrany spir.wikidot.com | |||
February 15, 2011 Re: Integer conversions too pedantic in 64-bit | ||||
|---|---|---|---|---|
| ||||
Posted in reply to spir | Am 15.02.2011 15:18, schrieb spir:
> On 02/15/2011 02:01 PM, Daniel Gibson wrote:
>> Am 15.02.2011 12:50, schrieb spir:
>>> On 02/15/2011 03:44 AM, Piotr Szturmaj wrote:
>>>> spir wrote:
>>>>> Rename size-t, or rather introduce a meaningful standard alias? (would
>>>>> vote for Natural)
>>>>
>>>> Maybe ptrint and ptruint?
>>>
>>> If ptr means pointer, then it's wrong: size-t is used for more than
>>> that, I guess. Strangely enough, while "size" may suggest it, .length
>>> does not return a size_t but an uint.
>>>
>>> Denis
>>
>> .length of what? An array?
>> I'm pretty sure it returns size_t.
>
> unittest {
> int[] ints; auto l = ints.length;
> writeln(typeof(l).stringof);
> }
> press play ;-)
>
> denis
void main() {
size_t x;
writefln(typeof(x).stringof);
}
try this, too ;-)
Because it's an alias the information about size_t gone at runtime and the "real" type is shown. uint in your case. (Here - gdc on amd64 - it's ulong).
Cheers,
- Daniel
| |||
February 15, 2011 Re: Integer conversions too pedantic in 64-bit | ||||
|---|---|---|---|---|
| ||||
Posted in reply to spir | spir wrote:
> press play
Since size_t is an alias, you wouldn't see it's name anywhere except the source code.
| |||
February 15, 2011 Re: Integer conversions too pedantic in 64-bit | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 02/15/2011 02:36 PM, Steven Schveighoffer wrote: > On Mon, 14 Feb 2011 20:58:17 -0500, Nick Sabalausky <a@a.a> wrote: > >> "Jonathan M Davis" <jmdavisProg@gmx.com> wrote in message >> news:mailman.1650.1297733226.4748.digitalmars-d@puremagic.com... >>> On Monday, February 14, 2011 17:06:43 spir wrote: >>>> >>>> Rename size-t, or rather introduce a meaningful standard alias? (would >>>> vote >>>> for Natural) >>> >>> Why? size_t is what's used in C++. It's well known and what lots of >>> programmers >>> would expect What would you gain by renaming it? >>> >> >> Although I fully realize how much this sounds like making a big deal out of >> nothing, to me, using "size_t" has always felt really clumsy and awkward. I >> think it's partly because of using an underscore in such an otherwise short >> identifier, and partly because I've been aware of size_t for years and still >> don't have the slightest clue WTF that "t" means. Something like "wordsize" >> would make a lot more sense and frankly feel much nicer. >> >> And, of course, there's a lot of well-known things in C++ that D >> deliberately destroys. D is a different language, it may as well do things >> better. > > Hey, bikeshedders, I found this cool easter-egg feature in D! It's called > alias! Don't like the name of something? Well you can change it! > > alias size_t wordsize; > > Now, you can use wordsize instead of size_t in your code, and the compiler > doesn't care! (in fact, that's all size_t is anyways *hint hint*) Sure, but it's not the point of this one bikeshedding thread. If you do that, then you're the only one who knows what "wordsize" means. Good, maybe, for app-specific semantic notions (alias Employee[] Staff;); certainly not for types at the highest degree of general purpose like size_t. We need a standard alias. Denis -- _________________ vita es estrany spir.wikidot.com | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply