{"thread":{"id":"10131","subject":"size_t vs \"unsigned long\"","startedAt":"2007-10-03T20:30:04Z","lastAt":"2007-10-05T06:27:05Z","messageCount":8,"participants":["Junio C Hamano","Pierre Habouzit","Jan Wielemaker","Florian Weimer","Kyle Moffett"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"54751","messageId":"7vabr0djqr.fsf@gitster.siamese.dyndns.org","threadId":"10131","inReplyTo":null,"subject":"size_t vs \"unsigned long\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-10-03T20:30:04Z","receivedAt":"2007-10-03T20:30:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Traditionally, inside git, we have used the length of things\nwith \"unsigned long\" for pretty much anything, except where we\nwanted the length exactly sized we used int32_t, uint64_t and\nfriends.\n\nA few places pass pointer to unsigned long as the second\nparameter to strbuf_detach(), triggering type mismatch warnings.\nAn easy way out is to change strbuf_detach() to take a pointer\nto ulong but I think it is going backwards.  Most places that\nuse \"unsigned long\" can safely be converted (and made more\ncorrect) to use size_t.\n\nAny opinions?\n"},{"id":"54753","messageId":"20071003204801.GC28188@artemis.corp","threadId":"10131","inReplyTo":"7vabr0djqr.fsf@gitster.siamese.dyndns.org","subject":"Re: size_t vs \"unsigned long\"","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-10-03T20:48:01Z","receivedAt":"2007-10-03T20:48:01Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Wed, Oct 03, 2007 at 08:30:04PM +0000, Junio C Hamano wrote:\n> Traditionally, inside git, we have used the length of things\n> with \"unsigned long\" for pretty much anything, except where we\n> wanted the length exactly sized we used int32_t, uint64_t and\n> friends.\n> \n> A few places pass pointer to unsigned long as the second\n> parameter to strbuf_detach(), triggering type mismatch warnings.\n> An easy way out is to change strbuf_detach() to take a pointer\n> to ulong but I think it is going backwards.  Most places that\n> use \"unsigned long\" can safely be converted (and made more\n> correct) to use size_t.\n\n  Well, afaict, on every linux archs I know of, unsigned longs and\nsize_t are the same. Though, I don't know if that holds for the msys\nport, and if that does not holds, then a s/unsigned long/size_t/ would\nhelp them. Else, for consistency sake, I believe the change is a good\none.\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"54754","messageId":"7v641newom.fsf@gitster.siamese.dyndns.org","threadId":"10131","inReplyTo":"20071003204801.GC28188@artemis.corp","subject":"Re: size_t vs \"unsigned long\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-10-03T21:05:13Z","receivedAt":"2007-10-03T21:05:13Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pierre Habouzit <madcoder@debian.org> writes:\n\n>   Well, afaict, on every linux archs I know of, unsigned longs and\n> size_t are the same. Though, I don't know if that holds for the msys\n> port, and if that does not holds, then a s/unsigned long/size_t/ would\n> help them. Else, for consistency sake, I believe the change is a good\n> one.\n\nFWIW, I am already getting bitten on a FC box with gcc 4.1.1\n20060525 that warns about the wrong type being passed, as I\nusually build things with -Werror; the issue is not just \"they\nare of the same underlying type\".\n"},{"id":"54756","messageId":"200710032320.00263.wielemak@science.uva.nl","threadId":"10131","inReplyTo":"20071003204801.GC28188@artemis.corp","subject":"Re: size_t vs \"unsigned long\"","fromName":"Jan Wielemaker","fromEmail":"wielemak@science.uva.nl","sentAt":"2007-10-03T21:19:59Z","receivedAt":"2007-10-03T21:19:59Z","isPatch":false,"sender":{"key":"wielemak@science.uva.nl","avatar":null},"body":"On Wednesday 03 October 2007 22:48, Pierre Habouzit wrote:\n> On Wed, Oct 03, 2007 at 08:30:04PM +0000, Junio C Hamano wrote:\n> > Traditionally, inside git, we have used the length of things\n> > with \"unsigned long\" for pretty much anything, except where we\n> > wanted the length exactly sized we used int32_t, uint64_t and\n> > friends.\n> >\n> > A few places pass pointer to unsigned long as the second\n> > parameter to strbuf_detach(), triggering type mismatch warnings.\n> > An easy way out is to change strbuf_detach() to take a pointer\n> > to ulong but I think it is going backwards.  Most places that\n> > use \"unsigned long\" can safely be converted (and made more\n> > correct) to use size_t.\n>\n>   Well, afaict, on every linux archs I know of, unsigned longs and\n> size_t are the same. Though, I don't know if that holds for the msys\n> port, and if that does not holds, then a s/unsigned long/size_t/ would\n> help them. Else, for consistency sake, I believe the change is a good\n> one.\n\nSurely on the Microsoft 64-bit compilers size_t is 64-bits and long is\n32-bits.  Don't blame me, I'm just the messenger that learned the hard\nway ...\n\n\t--- Jan\n"},{"id":"54759","messageId":"20071003213601.GD28188@artemis.corp","threadId":"10131","inReplyTo":"200710032320.00263.wielemak@science.uva.nl","subject":"Re: size_t vs \"unsigned long\"","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-10-03T21:36:01Z","receivedAt":"2007-10-03T21:36:01Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Wed, Oct 03, 2007 at 09:19:59PM +0000, Jan Wielemaker wrote:\n> On Wednesday 03 October 2007 22:48, Pierre Habouzit wrote:\n> > On Wed, Oct 03, 2007 at 08:30:04PM +0000, Junio C Hamano wrote:\n> > > Traditionally, inside git, we have used the length of things\n> > > with \"unsigned long\" for pretty much anything, except where we\n> > > wanted the length exactly sized we used int32_t, uint64_t and\n> > > friends.\n> > >\n> > > A few places pass pointer to unsigned long as the second\n> > > parameter to strbuf_detach(), triggering type mismatch warnings.\n> > > An easy way out is to change strbuf_detach() to take a pointer\n> > > to ulong but I think it is going backwards.  Most places that\n> > > use \"unsigned long\" can safely be converted (and made more\n> > > correct) to use size_t.\n> >\n> >   Well, afaict, on every linux archs I know of, unsigned longs and\n> > size_t are the same. Though, I don't know if that holds for the msys\n> > port, and if that does not holds, then a s/unsigned long/size_t/ would\n> > help them. Else, for consistency sake, I believe the change is a good\n> > one.\n> \n> Surely on the Microsoft 64-bit compilers size_t is 64-bits and long is\n> 32-bits.  Don't blame me, I'm just the messenger that learned the hard\n> way ...\n\n  Yeah, I've been wondering, and it's the information I had. well, the\ninformation I had is that sizeof(size_t) is 4 on win32, and 8 on win64,\nOTOH (and this one I'm sure), on windows, longs are 32bits on both (32\nand 64 bits ABIs).\n\n  So replacing unsigned long with size_t's will help the msys port,\nhence I had some insight that this could prove useful, now I'm sure :)\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"54760","messageId":"877im3khj0.fsf@mid.deneb.enyo.de","threadId":"10131","inReplyTo":"20071003204801.GC28188@artemis.corp","subject":"Re: size_t vs \"unsigned long\"","fromName":"Florian Weimer","fromEmail":"fw@deneb.enyo.de","sentAt":"2007-10-03T21:36:03Z","receivedAt":"2007-10-03T21:36:03Z","isPatch":false,"sender":{"key":"fw@deneb.enyo.de","avatar":null},"body":"* Pierre Habouzit:\n\n>   Well, afaict, on every linux archs I know of, unsigned longs and\n> size_t are the same.\n\nIIRC, 64-bit Windows uses 64-bit points (duh) and hence a 64-bit\nsize_t, but still has got 32-bit longs.  Documentation is a bit sparse\non this matter (because you are supposed to use LONG, DWORD and\nfriends anyway).\n"},{"id":"54795","messageId":"200710040916.55998.wielemak@science.uva.nl","threadId":"10131","inReplyTo":"20071003213601.GD28188@artemis.corp","subject":"Re: size_t vs \"unsigned long\"","fromName":"Jan Wielemaker","fromEmail":"wielemak@science.uva.nl","sentAt":"2007-10-04T07:16:55Z","receivedAt":"2007-10-04T07:16:55Z","isPatch":false,"sender":{"key":"wielemak@science.uva.nl","avatar":null},"body":"On Wednesday 03 October 2007 23:36, Pierre Habouzit wrote:\n> On Wed, Oct 03, 2007 at 09:19:59PM +0000, Jan Wielemaker wrote:\n> > On Wednesday 03 October 2007 22:48, Pierre Habouzit wrote:\n> > > On Wed, Oct 03, 2007 at 08:30:04PM +0000, Junio C Hamano wrote:\n> > > > Traditionally, inside git, we have used the length of things\n> > > > with \"unsigned long\" for pretty much anything, except where we\n> > > > wanted the length exactly sized we used int32_t, uint64_t and\n> > > > friends.\n> > > >\n> > > > A few places pass pointer to unsigned long as the second\n> > > > parameter to strbuf_detach(), triggering type mismatch warnings.\n> > > > An easy way out is to change strbuf_detach() to take a pointer\n> > > > to ulong but I think it is going backwards.  Most places that\n> > > > use \"unsigned long\" can safely be converted (and made more\n> > > > correct) to use size_t.\n> > >\n> > >   Well, afaict, on every linux archs I know of, unsigned longs and\n> > > size_t are the same. Though, I don't know if that holds for the msys\n> > > port, and if that does not holds, then a s/unsigned long/size_t/ would\n> > > help them. Else, for consistency sake, I believe the change is a good\n> > > one.\n> >\n> > Surely on the Microsoft 64-bit compilers size_t is 64-bits and long is\n> > 32-bits.  Don't blame me, I'm just the messenger that learned the hard\n> > way ...\n>\n>   Yeah, I've been wondering, and it's the information I had. well, the\n> information I had is that sizeof(size_t) is 4 on win32, and 8 on win64,\n> OTOH (and this one I'm sure), on windows, longs are 32bits on both (32\n> and 64 bits ABIs).\n>\n>   So replacing unsigned long with size_t's will help the msys port,\n> hence I had some insight that this could prove useful, now I'm sure :)\n\nThe other types that are useful are intptr_t and uintptr_t, integers\nthat are guaranteed to be able to hold a pointer. They are defined by\nrecent versions of the Microsoft compilers and are in <inttypes.h> in\nmost POSIX systems (at least I didn't have complaints since I started\nusing them).  I use them for integers holding mangled pointers.  Of\ncourse most clean C programs should not need that.\n\n\t--- Jan\n"},{"id":"54907","messageId":"620B5C1C-CFE8-401B-8BC7-D89C8740D63B@mac.com","threadId":"10131","inReplyTo":"877im3khj0.fsf@mid.deneb.enyo.de","subject":"Re: size_t vs \"unsigned long\"","fromName":"Kyle Moffett","fromEmail":"mrmacman_g4@mac.com","sentAt":"2007-10-05T06:27:05Z","receivedAt":"2007-10-05T06:27:05Z","isPatch":false,"sender":{"key":"mrmacman_g4@mac.com","avatar":null},"body":"On Oct 03, 2007, at 17:36:03, Florian Weimer wrote:\n> * Pierre Habouzit:\n>> Well, afaict, on every linux archs I know of, unsigned longs and  \n>> size_t are the same.\n>\n> IIRC, 64-bit Windows uses 64-bit points (duh) and hence a 64-bit  \n> size_t, but still has got 32-bit longs.  Documentation is a bit  \n> sparse on this matter (because you are supposed to use LONG, DWORD  \n> and friends anyway).\n\nFor reference, Linux is always an LP32 (long-and-pointer-are-32-bit)  \nor LP64 (long-and-pointer-are-64-bit) platform.  On the other hand,  \nfor crappy backwards-compat reasons, Windows is either LP32 or LLP64  \n(long-long-and-pointer-are-64-bit).  I think most of the remaining  \nUNIXes fall into the LP32/LP64 category, the LLP64 platforms are  \nfairly rare (thankfully).\n\nCheers,\nKyle Moffett\n"}]}