test-endian-sign-conversion.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Test endian.h endian-conversion macros work with -Wsign-conversion.
  2. Copyright (C) 2018-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <endian.h>
  16. #include <stdint.h>
  17. uint16_t u16;
  18. uint32_t u32;
  19. uint64_t u64;
  20. static int
  21. do_test (void)
  22. {
  23. /* This is a compilation test. */
  24. u16 = (htobe16 (u16));
  25. u16 = (htole16 (u16));
  26. u16 = (be16toh (u16));
  27. u16 = (le16toh (u16));
  28. u32 = (htobe32 (u32));
  29. u32 = (htole32 (u32));
  30. u32 = (be32toh (u32));
  31. u32 = (le32toh (u32));
  32. u64 = (htobe64 (u64));
  33. u64 = (htole64 (u64));
  34. u64 = (be64toh (u64));
  35. u64 = (le64toh (u64));
  36. (void) u16;
  37. (void) u32;
  38. (void) u64;
  39. return 0;
  40. }
  41. #include <support/test-driver.c>