return to Laboratorio de Sistemas Embebidos
(all the credits to aiju.de)
experienced programmer
static int zeroes(int *a, int i)
{
while(i--)
if(*a++ != 0)
return 0;
return 1;
}
inexperienced programmer
int IsOnlyZeroes(int iArray[], int iCount)
{
int Index, Result;
Result = 1; /* set result to 1 */
for(Index = 0; Index < iCount; Index++) /* iterate */
{
if(iArray[Index] == 0) /* check if zero */
{
Result = 0; /* set result to 0 */
}
}
return Result; /* return result */
}
Windows programmer
DWORD IsNotOnlyZeroesEx(LPDWORD dwArray, DWORD dwCount, LPSECURITYATTRIBUTES lpSecurityAttributes, LPMYSTERY lpMysteryPointer);
/* implementation is secret */
C++ Programmer
/* god i hate this limited language */
int is_only_zeroes(integer_array *a)
{
integer_iterator *i;
bool r;
i = new_integer_iterator(a);
r = true;
while(!integer_iterator_has_hit_end(i)){
r = r && dereference_integer_iterator(i);
advance_integer_iterator(i);
}
delete_integer_iterator(i);
return r;
}
Functional Programmer
int iszero(int i)
{
return i == 0;
}
int isnotzeroes(int *a, int i)
{
return !fold(and, map(iszero, a, i), i);
}
int iszeroes(int *a, int i)
{
return !isnotzeroes(a, i);
}
GNOME Programmer
#define ISZERO isnils
#define isnils iszeroes
#define iszeroes zeroes
INTEGER zeroes(INTEGER *a, int i)
{
FOR_LOOP(j,0,i)
COMPARE_ARRAY_ELEMENT(a,i,return 0);
return 1;
}
GNU Programmer
int zeroes(int *a, int i, int version)
{
if(version){
printf("zeroes v0.9\n");
printf("(C) Whatever\n");
}
printf("By Using This Routine You Agree To The Terms of The GNU General Public License 4 or newer, reproduced below\n");
...
}
Linux Programmer
inline int __attributes__((integer_manipulating_routine)) zeroes(int *a, int __attributes__((count_parameter)) i)
{
char *b;
int rc;
OPTIMIZE_ME_HARDER;
USE_SSE13;
#if defined(I386) && !defined(STRANGESHIT)
__asm__(.......);
#else
b = FASTMALLOC(sizeof(int) * i);
OPTIMIZE_BRANCH assert(b);
rc = memcmp(a, b, sizeof(int) * i);
FASTFREE(b);
#endif
return rc;
}