summaryrefslogtreecommitdiff
path: root/utils/static_utoa.h
blob: 3af9fbb6958a876356951e4792e3f7d71eb911c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef STATIC_UTOA_H
#define STATIC_UTOA_H

#include "threadlocal.h"
#include "utoa.h"

namespace {
THREADLOCAL char utoa_buf[utoa_bufsize]; // to put end of string character at buf[20]
}

inline char *static_utoa(unsigned n) {
  return utoa(utoa_buf+utoa_bufsizem1,n);
}

inline char *static_itoa(int n) {
  return itoa(utoa_buf+utoa_bufsizem1,n);
}

#ifdef ITOA_SAMPLE
# include <cstdio>
# include <sstream>
# include <iostream>
using namespace std;

int main(int argc,char *argv[]) {
  printf("d U d U d U\n");
  for (int i=1;i<argc;++i) {
    int n;
    unsigned un;
    sscanf(argv[i],"%d",&n);
    sscanf(argv[i],"%u",&un);
    printf("%d %u %s",n,un,static_itoa(n));
    printf(" %s %s %s\n",static_utoa(un),itos(n).c_str(),utos(un).c_str());
  }
  return 0;
}
#endif

#endif