Re: [algogeeks] Re: questions related to C

2011-07-12 Thread Neeraj Gupta
http://www.cplusplus.com/reference/algorithm/swap/ On Wed, Jul 13, 2011 at 10:40 AM, Aniket Dutta wrote: > what about a generic swap function which works for structures also? > > > On Wed, Jul 13, 2011 at 2:23 AM, Don wrote: > >> To check for overflow, use condition: >> >> if (b > (maxuint-a)) >

Re: [algogeeks] Re: questions related to C

2011-07-12 Thread Sandeep Jain
Try it. It should work fine. Regards, Sandeep Jain On Wed, Jul 13, 2011 at 10:40 AM, Aniket Dutta wrote: > what about a generic swap function which works for structures also? > > > On Wed, Jul 13, 2011 at 2:23 AM, Don wrote: > >> To check for overflow, use condition: >> >> if (b > (maxuint-a

Re: [algogeeks] Re: questions related to C

2011-07-12 Thread Aniket Dutta
what about a generic swap function which works for structures also? On Wed, Jul 13, 2011 at 2:23 AM, Don wrote: > To check for overflow, use condition: > > if (b > (maxuint-a)) > return error; > > Where maxuint is the largest value which can be stored in an unsigned > integer. > > Don > > On Ju

[algogeeks] Re: questions related to C

2011-07-12 Thread Don
To check for overflow, use condition: if (b > (maxuint-a)) return error; Where maxuint is the largest value which can be stored in an unsigned integer. Don On Jul 8, 5:50 am, vikas wrote: > Q1 - write a generic macro to swap two values (int,float,double,pointers as > well ) > > Q2 - Implemen

Re: [algogeeks] Re: questions related to C

2011-07-12 Thread hary rathor
#define SWAP(f,type) f(type x, type y)\ {\ type z; z=x, x=y,y=z; \ } swap(M_INT, int) swap(M_FLT,float) swap(m_double,double) int main() { int p =5,q=4; float r=5.4,s=6.9; double v=6.5,w=6.9; swap(p,q); swap(r,s); swap(v,w); } -- You received this message because you are subscribed to the Go

[algogeeks] Re: questions related to C

2011-07-12 Thread Dave
@Tendura: This violates the sequence point rule. Results are undefined. Dave On Jul 12, 2:02 pm, tendua <6fae1ce6347...@gmail.com> wrote: > regarding question to the generic macro to swap int, float, double > > # define swap(a,b) ((a)^=(b)^=(a)^=(b)) > > On Jul 12, 10:08 pm, Aniket Dutta wrote:

[algogeeks] Re: questions related to C

2011-07-12 Thread tendua
regarding question to the generic macro to swap int, float, double # define swap(a,b) ((a)^=(b)^=(a)^=(b)) On Jul 12, 10:08 pm, Aniket Dutta wrote: > c=a+b > then find b=c-a; > if this b equals previous one then ok else overflow > > On 7/9/11, John Hayes wrote: > > > regarding question relate