* size_t vs "unsigned long" @ 2007-10-03 20:30 Junio C Hamano 2007-10-03 20:48 ` Pierre Habouzit 0 siblings, 1 reply; 8+ messages in thread From: Junio C Hamano @ 2007-10-03 20:30 UTC (permalink / raw) To: git; +Cc: Pierre Habouzit Traditionally, inside git, we have used the length of things with "unsigned long" for pretty much anything, except where we wanted the length exactly sized we used int32_t, uint64_t and friends. A few places pass pointer to unsigned long as the second parameter to strbuf_detach(), triggering type mismatch warnings. An easy way out is to change strbuf_detach() to take a pointer to ulong but I think it is going backwards. Most places that use "unsigned long" can safely be converted (and made more correct) to use size_t. Any opinions? ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: size_t vs "unsigned long" 2007-10-03 20:30 size_t vs "unsigned long" Junio C Hamano @ 2007-10-03 20:48 ` Pierre Habouzit 2007-10-03 21:05 ` Junio C Hamano ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Pierre Habouzit @ 2007-10-03 20:48 UTC (permalink / raw) To: Junio C Hamano; +Cc: git [-- Attachment #1: Type: text/plain, Size: 1092 bytes --] On Wed, Oct 03, 2007 at 08:30:04PM +0000, Junio C Hamano wrote: > Traditionally, inside git, we have used the length of things > with "unsigned long" for pretty much anything, except where we > wanted the length exactly sized we used int32_t, uint64_t and > friends. > > A few places pass pointer to unsigned long as the second > parameter to strbuf_detach(), triggering type mismatch warnings. > An easy way out is to change strbuf_detach() to take a pointer > to ulong but I think it is going backwards. Most places that > use "unsigned long" can safely be converted (and made more > correct) to use size_t. Well, afaict, on every linux archs I know of, unsigned longs and size_t are the same. Though, I don't know if that holds for the msys port, and if that does not holds, then a s/unsigned long/size_t/ would help them. Else, for consistency sake, I believe the change is a good one. -- ·O· Pierre Habouzit ··O madcoder@debian.org OOO http://www.madism.org [-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: size_t vs "unsigned long" 2007-10-03 20:48 ` Pierre Habouzit @ 2007-10-03 21:05 ` Junio C Hamano 2007-10-03 21:19 ` Jan Wielemaker 2007-10-03 21:36 ` Florian Weimer 2 siblings, 0 replies; 8+ messages in thread From: Junio C Hamano @ 2007-10-03 21:05 UTC (permalink / raw) To: Pierre Habouzit; +Cc: git Pierre Habouzit <madcoder@debian.org> writes: > Well, afaict, on every linux archs I know of, unsigned longs and > size_t are the same. Though, I don't know if that holds for the msys > port, and if that does not holds, then a s/unsigned long/size_t/ would > help them. Else, for consistency sake, I believe the change is a good > one. FWIW, I am already getting bitten on a FC box with gcc 4.1.1 20060525 that warns about the wrong type being passed, as I usually build things with -Werror; the issue is not just "they are of the same underlying type". ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: size_t vs "unsigned long" 2007-10-03 20:48 ` Pierre Habouzit 2007-10-03 21:05 ` Junio C Hamano @ 2007-10-03 21:19 ` Jan Wielemaker 2007-10-03 21:36 ` Pierre Habouzit 2007-10-03 21:36 ` Florian Weimer 2 siblings, 1 reply; 8+ messages in thread From: Jan Wielemaker @ 2007-10-03 21:19 UTC (permalink / raw) To: Pierre Habouzit; +Cc: Junio C Hamano, git On Wednesday 03 October 2007 22:48, Pierre Habouzit wrote: > On Wed, Oct 03, 2007 at 08:30:04PM +0000, Junio C Hamano wrote: > > Traditionally, inside git, we have used the length of things > > with "unsigned long" for pretty much anything, except where we > > wanted the length exactly sized we used int32_t, uint64_t and > > friends. > > > > A few places pass pointer to unsigned long as the second > > parameter to strbuf_detach(), triggering type mismatch warnings. > > An easy way out is to change strbuf_detach() to take a pointer > > to ulong but I think it is going backwards. Most places that > > use "unsigned long" can safely be converted (and made more > > correct) to use size_t. > > Well, afaict, on every linux archs I know of, unsigned longs and > size_t are the same. Though, I don't know if that holds for the msys > port, and if that does not holds, then a s/unsigned long/size_t/ would > help them. Else, for consistency sake, I believe the change is a good > one. Surely on the Microsoft 64-bit compilers size_t is 64-bits and long is 32-bits. Don't blame me, I'm just the messenger that learned the hard way ... --- Jan ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: size_t vs "unsigned long" 2007-10-03 21:19 ` Jan Wielemaker @ 2007-10-03 21:36 ` Pierre Habouzit 2007-10-04 7:16 ` Jan Wielemaker 0 siblings, 1 reply; 8+ messages in thread From: Pierre Habouzit @ 2007-10-03 21:36 UTC (permalink / raw) To: Jan Wielemaker; +Cc: Junio C Hamano, git [-- Attachment #1: Type: text/plain, Size: 1834 bytes --] On Wed, Oct 03, 2007 at 09:19:59PM +0000, Jan Wielemaker wrote: > On Wednesday 03 October 2007 22:48, Pierre Habouzit wrote: > > On Wed, Oct 03, 2007 at 08:30:04PM +0000, Junio C Hamano wrote: > > > Traditionally, inside git, we have used the length of things > > > with "unsigned long" for pretty much anything, except where we > > > wanted the length exactly sized we used int32_t, uint64_t and > > > friends. > > > > > > A few places pass pointer to unsigned long as the second > > > parameter to strbuf_detach(), triggering type mismatch warnings. > > > An easy way out is to change strbuf_detach() to take a pointer > > > to ulong but I think it is going backwards. Most places that > > > use "unsigned long" can safely be converted (and made more > > > correct) to use size_t. > > > > Well, afaict, on every linux archs I know of, unsigned longs and > > size_t are the same. Though, I don't know if that holds for the msys > > port, and if that does not holds, then a s/unsigned long/size_t/ would > > help them. Else, for consistency sake, I believe the change is a good > > one. > > Surely on the Microsoft 64-bit compilers size_t is 64-bits and long is > 32-bits. Don't blame me, I'm just the messenger that learned the hard > way ... Yeah, I've been wondering, and it's the information I had. well, the information I had is that sizeof(size_t) is 4 on win32, and 8 on win64, OTOH (and this one I'm sure), on windows, longs are 32bits on both (32 and 64 bits ABIs). So replacing unsigned long with size_t's will help the msys port, hence I had some insight that this could prove useful, now I'm sure :) -- ·O· Pierre Habouzit ··O madcoder@debian.org OOO http://www.madism.org [-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: size_t vs "unsigned long" 2007-10-03 21:36 ` Pierre Habouzit @ 2007-10-04 7:16 ` Jan Wielemaker 0 siblings, 0 replies; 8+ messages in thread From: Jan Wielemaker @ 2007-10-04 7:16 UTC (permalink / raw) To: git On Wednesday 03 October 2007 23:36, Pierre Habouzit wrote: > On Wed, Oct 03, 2007 at 09:19:59PM +0000, Jan Wielemaker wrote: > > On Wednesday 03 October 2007 22:48, Pierre Habouzit wrote: > > > On Wed, Oct 03, 2007 at 08:30:04PM +0000, Junio C Hamano wrote: > > > > Traditionally, inside git, we have used the length of things > > > > with "unsigned long" for pretty much anything, except where we > > > > wanted the length exactly sized we used int32_t, uint64_t and > > > > friends. > > > > > > > > A few places pass pointer to unsigned long as the second > > > > parameter to strbuf_detach(), triggering type mismatch warnings. > > > > An easy way out is to change strbuf_detach() to take a pointer > > > > to ulong but I think it is going backwards. Most places that > > > > use "unsigned long" can safely be converted (and made more > > > > correct) to use size_t. > > > > > > Well, afaict, on every linux archs I know of, unsigned longs and > > > size_t are the same. Though, I don't know if that holds for the msys > > > port, and if that does not holds, then a s/unsigned long/size_t/ would > > > help them. Else, for consistency sake, I believe the change is a good > > > one. > > > > Surely on the Microsoft 64-bit compilers size_t is 64-bits and long is > > 32-bits. Don't blame me, I'm just the messenger that learned the hard > > way ... > > Yeah, I've been wondering, and it's the information I had. well, the > information I had is that sizeof(size_t) is 4 on win32, and 8 on win64, > OTOH (and this one I'm sure), on windows, longs are 32bits on both (32 > and 64 bits ABIs). > > So replacing unsigned long with size_t's will help the msys port, > hence I had some insight that this could prove useful, now I'm sure :) The other types that are useful are intptr_t and uintptr_t, integers that are guaranteed to be able to hold a pointer. They are defined by recent versions of the Microsoft compilers and are in <inttypes.h> in most POSIX systems (at least I didn't have complaints since I started using them). I use them for integers holding mangled pointers. Of course most clean C programs should not need that. --- Jan ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: size_t vs "unsigned long" 2007-10-03 20:48 ` Pierre Habouzit 2007-10-03 21:05 ` Junio C Hamano 2007-10-03 21:19 ` Jan Wielemaker @ 2007-10-03 21:36 ` Florian Weimer 2007-10-05 6:27 ` Kyle Moffett 2 siblings, 1 reply; 8+ messages in thread From: Florian Weimer @ 2007-10-03 21:36 UTC (permalink / raw) To: Pierre Habouzit; +Cc: Junio C Hamano, git * Pierre Habouzit: > Well, afaict, on every linux archs I know of, unsigned longs and > size_t are the same. IIRC, 64-bit Windows uses 64-bit points (duh) and hence a 64-bit size_t, but still has got 32-bit longs. Documentation is a bit sparse on this matter (because you are supposed to use LONG, DWORD and friends anyway). ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: size_t vs "unsigned long" 2007-10-03 21:36 ` Florian Weimer @ 2007-10-05 6:27 ` Kyle Moffett 0 siblings, 0 replies; 8+ messages in thread From: Kyle Moffett @ 2007-10-05 6:27 UTC (permalink / raw) To: Florian Weimer; +Cc: Pierre Habouzit, Junio C Hamano, git On Oct 03, 2007, at 17:36:03, Florian Weimer wrote: > * Pierre Habouzit: >> Well, afaict, on every linux archs I know of, unsigned longs and >> size_t are the same. > > IIRC, 64-bit Windows uses 64-bit points (duh) and hence a 64-bit > size_t, but still has got 32-bit longs. Documentation is a bit > sparse on this matter (because you are supposed to use LONG, DWORD > and friends anyway). For reference, Linux is always an LP32 (long-and-pointer-are-32-bit) or LP64 (long-and-pointer-are-64-bit) platform. On the other hand, for crappy backwards-compat reasons, Windows is either LP32 or LLP64 (long-long-and-pointer-are-64-bit). I think most of the remaining UNIXes fall into the LP32/LP64 category, the LLP64 platforms are fairly rare (thankfully). Cheers, Kyle Moffett ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-10-05 6:35 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2007-10-03 20:30 size_t vs "unsigned long" Junio C Hamano 2007-10-03 20:48 ` Pierre Habouzit 2007-10-03 21:05 ` Junio C Hamano 2007-10-03 21:19 ` Jan Wielemaker 2007-10-03 21:36 ` Pierre Habouzit 2007-10-04 7:16 ` Jan Wielemaker 2007-10-03 21:36 ` Florian Weimer 2007-10-05 6:27 ` Kyle Moffett
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).