cgul_defensive.h File Reference

defensive addition More...

#include "cgul_common.h"
#include "cgul_exception.h"
Include dependency graph for cgul_defensive.h:
This graph shows which files directly or indirectly include this file:

Functions

CGUL_BEGIN_C CGUL_EXPORT char cgul_defensive__add_char (cgul_exception_t *cex, char x1, char x2)
 
CGUL_EXPORT signed char cgul_defensive__add_signed_char (cgul_exception_t *cex, signed char x1, signed char x2)
 
CGUL_EXPORT unsigned char cgul_defensive__add_unsigned_char (cgul_exception_t *cex, unsigned char x1, unsigned char x2)
 
CGUL_EXPORT short cgul_defensive__add_short (cgul_exception_t *cex, short x1, short x2)
 
CGUL_EXPORT unsigned short cgul_defensive__add_unsigned_short (cgul_exception_t *cex, unsigned short x1, unsigned short x2)
 
CGUL_EXPORT int cgul_defensive__add_int (cgul_exception_t *cex, int x1, int x2)
 
CGUL_EXPORT unsigned int cgul_defensive__add_unsigned (cgul_exception_t *cex, unsigned int x1, unsigned int x2)
 
CGUL_EXPORT long cgul_defensive__add_long (cgul_exception_t *cex, long x1, long x2)
 
CGUL_EXPORT unsigned long cgul_defensive__add_unsigned_long (cgul_exception_t *cex, unsigned long x1, unsigned long x2)
 
CGUL_EXPORT size_t cgul_defensive__add_size_type (cgul_exception_t *cex, size_t x1, size_t x2)
 

Detailed Description

Defensive addition operations that add two positive addends and throw an exception if overflow is detected.

Author
Paul Serice

Function Documentation

§ cgul_defensive__add_char()

CGUL_BEGIN_C CGUL_EXPORT char cgul_defensive__add_char ( cgul_exception_t cex,
char  x1,
char  x2 
)

This function detects whether the char type is signed or unsigned and forwards the call to either cgul_defensive__add_signed_char() or cgul_defensive__add_unsigned_char() whichever is correct.

Parameters
[in,out]cexc-style exception
[in]x1first positive addend
[in]x2second positive addend
Returns
x1 + x2
See also
cgul_defensive__add_signed_char
cgul_defensive__add_unsigned_char

§ cgul_defensive__add_signed_char()

CGUL_EXPORT signed char cgul_defensive__add_signed_char ( cgul_exception_t cex,
signed char  x1,
signed char  x2 
)

This function returns the sum of the positive addends x1 and x2. If overflow or negative addends are detected, an exception is thrown, and 0 is returned.

Parameters
[in,out]cexc-style exception
[in]x1first positive addend
[in]x2second positive addend
Returns
x1 + x2

§ cgul_defensive__add_unsigned_char()

CGUL_EXPORT unsigned char cgul_defensive__add_unsigned_char ( cgul_exception_t cex,
unsigned char  x1,
unsigned char  x2 
)

This function returns the sum of the addends x1 and x2. If overflow is detected, an exception is thrown, and 0 is returned.

Parameters
[in,out]cexc-style exception
[in]x1first addend
[in]x2second addend
Returns
x1 + x2

§ cgul_defensive__add_short()

CGUL_EXPORT short cgul_defensive__add_short ( cgul_exception_t cex,
short  x1,
short  x2 
)

This function returns the sum of the positive addends x1 and x2. If overflow or negative addends are detected, an exception is thrown, and 0 is returned.

Parameters
[in,out]cexc-style exception
[in]x1first positive addend
[in]x2second positive addend
Returns
x1 + x2

§ cgul_defensive__add_unsigned_short()

CGUL_EXPORT unsigned short cgul_defensive__add_unsigned_short ( cgul_exception_t cex,
unsigned short  x1,
unsigned short  x2 
)

This function returns the sum of the addends x1 and x2. If overflow is detected, an exception is thrown, and 0 is returned.

Parameters
[in,out]cexc-style exception
[in]x1first addend
[in]x2second addend
Returns
x1 + x2

§ cgul_defensive__add_int()

CGUL_EXPORT int cgul_defensive__add_int ( cgul_exception_t cex,
int  x1,
int  x2 
)

This function returns the sum of the positive addends x1 and x2. If overflow or negative addends are detected, an exception is thrown, and 0 is returned.

Parameters
[in,out]cexc-style exception
[in]x1first positive addend
[in]x2second positive addend
Returns
x1 + x2

§ cgul_defensive__add_unsigned()

CGUL_EXPORT unsigned int cgul_defensive__add_unsigned ( cgul_exception_t cex,
unsigned int  x1,
unsigned int  x2 
)

This function returns the sum of the addends x1 and x2. If overflow is detected, an exception is thrown, and 0 is returned.

Parameters
[in,out]cexc-style exception
[in]x1first addend
[in]x2second addend
Returns
x1 + x2

§ cgul_defensive__add_long()

CGUL_EXPORT long cgul_defensive__add_long ( cgul_exception_t cex,
long  x1,
long  x2 
)

This function returns the sum of the positive addends x1 and x2. If overflow or negative addends are detected, an exception is thrown, and 0 is returned.

Parameters
[in,out]cexc-style exception
[in]x1first positive addend
[in]x2second positive addend
Returns
x1 + x2

§ cgul_defensive__add_unsigned_long()

CGUL_EXPORT unsigned long cgul_defensive__add_unsigned_long ( cgul_exception_t cex,
unsigned long  x1,
unsigned long  x2 
)

This function returns the sum of the addends x1 and x2. If overflow is detected, an exception is thrown, and 0 is returned.

Parameters
[in,out]cexc-style exception
[in]x1first addend
[in]x2second addend
Returns
x1 + x2

§ cgul_defensive__add_size_type()

CGUL_EXPORT size_t cgul_defensive__add_size_type ( cgul_exception_t cex,
size_t  x1,
size_t  x2 
)

This function returns the sum of the addends x1 and x2. If overflow is detected, an exception is thrown, and 0 is returned.

Parameters
[in,out]cexc-style exception
[in]x1first addend
[in]x2second addend
Returns
x1 + x2