multiInclude.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Multi-include test program
  3. * Validates that xxhash.h can be included multiple times and in any order
  4. *
  5. * Copyright (C) 2020 Yann Collet
  6. *
  7. * GPL v2 License
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. *
  23. * You can contact the author at:
  24. * - xxHash homepage: https://www.xxhash.com
  25. * - xxHash source repository: https://github.com/Cyan4973/xxHash
  26. */
  27. #include <stdio.h> /* printf */
  28. /* Normal include, gives access to public symbols */
  29. #include "../xxhash.h"
  30. /* Multiple consecutive inclusions are handled properly. */
  31. #include "../xxhash.h"
  32. /*
  33. * Advanced include, gives access to experimental symbols
  34. * This test ensures that xxhash.h can be included multiple times
  35. * and in any order. The tested order is more difficult:
  36. * without care, the declaration of experimental symbols could be skipped.
  37. */
  38. #define XXH_STATIC_LINKING_ONLY
  39. #include "../xxhash.h"
  40. /*
  41. * Inlining: redefine all identifiers, keep them private to the unit.
  42. * Note: Without specific efforts, the identifier names would collide.
  43. *
  44. * To be linked with and without xxhash.o
  45. * to test the symbol's presence and naming collisions.
  46. */
  47. #define XXH_INLINE_ALL
  48. #include "../xxhash.h"
  49. /*
  50. * Multiple consecutive inclusions with XXH_INLINE_ALL are handled properly.
  51. */
  52. #define XXH_INLINE_ALL
  53. #include "../xxhash.h"
  54. void hash_advanced(void)
  55. {
  56. XXH3_state_t state; /* this type is part of experimental API */
  57. XXH3_64bits_reset(&state);
  58. const char input[] = "Hello World !";
  59. XXH3_64bits_update(&state, input, sizeof(input));
  60. XXH64_hash_t const h = XXH3_64bits_digest(&state);
  61. printf("hash '%s': %08x%08x \n", input, (unsigned)(h >> 32), (unsigned)h);
  62. }
  63. int main(void)
  64. {
  65. hash_advanced();
  66. }