[asterisk-dev] [Code Review] Unit Test: verify aggregate device state mapping and device to extension state mapping.

Kevin Fleming kpfleming at digium.com
Wed Feb 17 13:23:00 CST 2010



> On 2010-02-17 11:55:59, Mark Michelson wrote:
> > /trunk/tests/test_devicestate.c, lines 233-235
> > <https://reviewboard.asterisk.org/r/516/diff/1/?file=8152#file8152line233>
> >
> >     I'd recommend, if possible, building on a 32-bit machine just to be sure that using %lu for a size_t doesn't cause a compiler warning. I've gotten in the habit of just casting them to an int and using %d in the format string.
> >     
> >     I think, though, that a size_t is generally a word-sized unsigned quantity, so %lu will probably work. I'd still double-check to be sure though.
> 
> David Vossel wrote:
>     good catch, you're right

Yes, the casting method works. The *proper* method is to use the GCC extensions for printf() that are designed for this purpose (%zu for size_t), but unfortunately we have people that build Asterisk on fairly old compilers that don't support these extensions... so the casting method is present in many places in the tree already. There's really no reason to use %lu if you are going to cast it anyway, unless you really expect the quantity being reported to be larger than an int can hold.

For reference: on an x86-32 system, 'int' is 32 bits, 'long int' is 64 bits, and 'size_t' is 32 bits; on an x86-64 system, 'int' is 32 bits, 'long int' is 64 bits, and 'size_t' is 64 bits. This is why you are seeing this issue. In general, size_t is going to be the same size as a pointer on the platform, because it has to be able to represent the largest object that could be held in memory.


- Kevin


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/516/#review1532
-----------------------------------------------------------


On 2010-02-17 11:29:02, David Vossel wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/516/
> -----------------------------------------------------------
> 
> (Updated 2010-02-17 11:29:02)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> New unit test to verify aggregate device state mapping and device to extension state mapping.
> 
> 
> Diffs
> -----
> 
>   /trunk/tests/test_devicestate.c PRE-CREATION 
> 
> Diff: https://reviewboard.asterisk.org/r/516/diff
> 
> 
> Testing
> -------
> 
> test runs and completes as expected.
> 
> 
> Thanks,
> 
> David
> 
>




More information about the asterisk-dev mailing list