to_text_ptr.cpp 584 B

1234567891011121314151617181920212223242526
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/to_text.h>
  5. #include<cstdio>
  6. namespace __vic {
  7. //----------------------------------------------------------------------------
  8. void to_text_append(const void *p, std::string &s)
  9. {
  10. char buf[sizeof p <= 8 ? 32 : -1]; // static_assert(sizeof p <= 8)
  11. size_t len =
  12. #if __cplusplus >= 201103L
  13. std::snprintf(buf, sizeof buf, "%p", p);
  14. if(len >= sizeof buf) len = sizeof buf - 1;
  15. #else
  16. std::sprintf(buf, "%p", p);
  17. #endif
  18. s.append(buf, len);
  19. }
  20. //----------------------------------------------------------------------------
  21. } // namespace