Back to index

glibc  2.9
tst-bswap.c
Go to the documentation of this file.
00001 /* Copyright (C) 2000 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@cygnus.com>.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <byteswap.h>
00021 #include <stdio.h>
00022 
00023 extern unsigned long long int wash (unsigned long long int a);
00024 
00025 int
00026 main (void)
00027 {
00028   int result = 0;
00029 
00030   /* Test the functions with constant arguments.  */
00031   if (bswap_16 (0x1234) != 0x3412)
00032     {
00033       puts ("bswap_16 (constant) flunked");
00034       result = 1;
00035     }
00036   if (bswap_32 (0x12345678) != 0x78563412)
00037     {
00038       puts ("bswap_32 (constant) flunked");
00039       result = 1;
00040     }
00041   if (bswap_64 (0x1234567890abcdefULL) != 0xefcdab9078563412ULL)
00042     {
00043       puts ("bswap_64 (constant) flunked");
00044       result = 1;
00045     }
00046 
00047   /* Test the functions with non-constant arguments.  */
00048   if (bswap_16 (wash (0x1234)) != 0x3412)
00049     {
00050       puts ("bswap_16 (non-constant) flunked");
00051       result = 1;
00052     }
00053   if (bswap_32 (wash (0x12345678)) != 0x78563412)
00054     {
00055       puts ("bswap_32 (non-constant) flunked");
00056       result = 1;
00057     }
00058   if (bswap_64 (wash (0x1234567890abcdefULL)) != 0xefcdab9078563412ULL)
00059     {
00060       puts ("bswap_64 (non-constant) flunked");
00061       result = 1;
00062     }
00063 
00064   return result;
00065 }
00066 
00067 
00068 unsigned long long int
00069 wash (unsigned long long int a)
00070 {
00071   /* Do nothing.  This function simply exists to avoid that the compiler
00072      regards the argument to the bswap_*() functions as constant.  */
00073   return a + 0;
00074 }