Skip to content

Commit a401e80

Browse files
authored
Merge pull request #610 from AnthonyDiGirolamo/cpp17-compatibility
Update itoa.c for -std=c++17 compatibility
2 parents be4d31c + df80616 commit a401e80

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

cores/nRF5/itoa.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,55 @@
2323
extern "C" {
2424
#endif
2525

26+
/* reverse: reverse string s in place */
27+
/*
28+
static void reverse( char s[] )
29+
{
30+
int i, j ;
31+
char c ;
32+
33+
for ( i = 0, j = strlen(s)-1 ; i < j ; i++, j-- )
34+
{
35+
c = s[i] ;
36+
s[i] = s[j] ;
37+
s[j] = c ;
38+
}
39+
}
40+
*/
41+
42+
/* itoa: convert n to characters in s */
43+
/*
44+
extern void itoa( int n, char s[] )
45+
{
46+
int i, sign ;
47+
48+
if ( (sign = n) < 0 ) // record sign
49+
{
50+
n = -n; // make n positive
51+
}
52+
53+
i = 0;
54+
do
55+
{ // generate digits in reverse order
56+
s[i++] = n % 10 + '0'; // get next digit
57+
} while ((n /= 10) > 0) ; // delete it
58+
59+
if (sign < 0 )
60+
{
61+
s[i++] = '-';
62+
}
63+
64+
s[i] = '\0';
65+
66+
reverse( s ) ;
67+
}
68+
*/
69+
70+
extern char* itoa( int value, char *string, int radix )
71+
{
72+
return ltoa( value, string, radix ) ;
73+
}
74+
2675
extern char* ltoa( long value, char *string, int radix )
2776
{
2877
char tmp[33];
@@ -73,6 +122,11 @@ extern char* ltoa( long value, char *string, int radix )
73122
return string;
74123
}
75124

125+
extern char* utoa( unsigned int value, char *string, int radix )
126+
{
127+
return ultoa( value, string, radix ) ;
128+
}
129+
76130
extern char* ultoa( unsigned long value, char *string, int radix )
77131
{
78132
char tmp[33];

cores/nRF5/itoa.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222
extern "C"{
2323
#endif
2424

25+
//extern void itoa( int n, char s[] ) ;
26+
27+
extern char* itoa( int value, char *string, int radix ) ;
2528
extern char* ltoa( long value, char *string, int radix ) ;
29+
extern char* utoa( unsigned int value, char *string, int radix ) ;
2630
extern char* ultoa( unsigned long value, char *string, int radix ) ;
2731

2832
#ifdef __cplusplus
2933
} // extern "C"
3034
#endif
35+

0 commit comments

Comments
 (0)