Re: side-effects/type safe min/max (Was Re: [1/3] d3dx9: Partial implementation of D3DXAssembleShader function. [try 2])

2010-02-05 Thread Michael Stefaniuc
On 02/05/2010 07:38 PM, Henri Verbeet wrote: On 5 February 2010 19:10, Michael Stefaniuc wrote: Henri Verbeet wrote: min and max are already defined in windef.h. Note that they're not safe for expressions with side-effects, but for simple expressions like the one here they're ok. We can lift

Re: side-effects/type safe min/max (Was Re: [1/3] d3dx9: Partial implementation of D3DXAssembleShader function. [try 2])

2010-02-05 Thread Henri Verbeet
On 5 February 2010 19:10, Michael Stefaniuc wrote: > Henri Verbeet wrote: >> min and max are already defined in windef.h. Note that they're not >> safe for expressions with side-effects, but for simple expressions >> like the one here they're ok. > We can lift the side-effects and type safe min/ma

side-effects/type safe min/max (Was Re: [1/3] d3dx9: Partial implementation of D3DXAssembleShader function. [try 2])

2010-02-05 Thread Michael Stefaniuc
Henri Verbeet wrote: > On 5 February 2010 18:19, Matteo Bruni wrote: >> Sure. Better to go with something like "len = len < (desc->size - >> desc->pos) ? len : desc->size - desc->pos" or creating a "min" >> function? >> > min and max are already defined in windef.h. Note that they're not > safe fo

Re: [1/3] d3dx9: Partial implementation of D3DXAssembleShader function. [try 2]

2010-02-05 Thread Henri Verbeet
On 5 February 2010 18:19, Matteo Bruni wrote: > Sure. Better to go with something like "len = len < (desc->size - > desc->pos) ? len : desc->size - desc->pos" or creating a "min" > function? > min and max are already defined in windef.h. Note that they're not safe for expressions with side-effects

Re: [1/3] d3dx9: Partial implementation of D3DXAssembleShader function. [try 2]

2010-02-05 Thread Matteo Bruni
Seems like I'm unable to review my code... > >> +    if(desc->pos + len > desc->size) len = desc->size - desc->pos; > It's usually safer to write expressions like that as "if (len > > desc->size - desc->pos)" because "desc->pos + len" can wrap around if > len is large, while "desc->size - desc->po

Re: [1/3] d3dx9: Partial implementation of D3DXAssembleShader function. [try 2]

2010-02-05 Thread Henri Verbeet
On 4 February 2010 19:26, Matteo Bruni wrote: > +void wpp_write_message_var(const char *fmt, ...) PRINTF_ATTR(1,2); > +void wpp_write_message_var(const char *fmt, ...) You can just do the following: +void PRINTF_ATTR(1,2) wpp_write_message_var(const char *fmt, ...) > +desc = HeapAlloc(Get