Back to index

glibc  2.9
Defines | Functions
test-ffs.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Defines

#define TEST(fct, type)

Functions

int main (void)

Define Documentation

#define TEST (   fct,
  type 
)
Value:
try (#fct, 0, fct ((type) 0), 0);                                    \
  for (i=0 ; i < 8 * sizeof (type); i++)                             \
    try (#fct, 1ll << i, fct (((type) 1) << i), i + 1);                     \
  for (i=0 ; i < 8 * sizeof (type) ; i++)                            \
    try (#fct, (~((type) 0) >> i) << i, fct ((~((type) 0) >> i) << i), i + 1);\
  try (#fct, 0x80008000, fct ((type) 0x80008000), 16)

Function Documentation

int main ( void  )

Definition at line 26 of file test-ffs.c.

{
  int failures = 0;
  int i;

  auto void try (const char *name, long long int param, int value,
               int expected);

  void try (const char *name, long long int param, int value, int expected)
    {
      if (value != expected)
       {
         printf ("%s(%#llx) expected %d got %d\n",
                name, param, expected, value);
         ++failures;
       }
      else
       printf ("%s(%#llx) as expected %d\n", name, param, value);
    }

#define TEST(fct, type) \
  try (#fct, 0, fct ((type) 0), 0);                                         \
  for (i=0 ; i < 8 * sizeof (type); i++)                             \
    try (#fct, 1ll << i, fct (((type) 1) << i), i + 1);                     \
  for (i=0 ; i < 8 * sizeof (type) ; i++)                            \
    try (#fct, (~((type) 0) >> i) << i, fct ((~((type) 0) >> i) << i), i + 1);\
  try (#fct, 0x80008000, fct ((type) 0x80008000), 16)

  TEST (ffs, int);
  TEST (ffsl, long int);
  TEST (ffsll, long long int);

  if (failures)
    printf ("Test FAILED!  %d failure%s.\n", failures, &"s"[failures == 1]);
  else
    puts ("Test succeeded.");

  return failures;
}

Here is the call graph for this function: