File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ // C++ for Arduino
2+ // Why C++ programmers stopped using NULL?
3+ //
4+ // Read the article:
5+ // https://cpp4arduino.com/2018/10/26/why-cpp-programmers-stopped-using-null.html
6+
7+ template <typename T>
8+ void printValue (T value);
9+
10+ template <>
11+ void printValue<int >(int value) {
12+ Serial.print (" Integer: " );
13+ Serial.println (value, DEC);
14+ }
15+
16+ template <>
17+ void printValue<void *>(void *value) {
18+ Serial.print (" Pointer: 0x" );
19+ Serial.println ((intptr_t )value, HEX);
20+ }
21+
22+ void setup () {
23+ Serial.begin (9600 );
24+ while (!Serial)
25+ continue ;
26+
27+ const char *color = NULL ;
28+ String colorStr1 (color);
29+ String colorStr2 (NULL );
30+
31+ if (colorStr1 == colorStr2) {
32+ Serial.println (" colorStr1 == colorStr2" );
33+ } else {
34+ Serial.println (" colorStr1 != colorStr2" );
35+ }
36+
37+ Serial.print (" colorStr1 = " );
38+ Serial.println (colorStr1);
39+ Serial.print (" colorStr2 = " );
40+ Serial.println (colorStr2);
41+
42+ printValue (42 );
43+ printValue ((void *)0x101 );
44+ printValue (NULL );
45+ }
46+
47+ void loop () {}
Original file line number Diff line number Diff line change 1+ # Why C++ programmers stopped using NULL?
2+
3+ Read the article on [ cpp4arduino.com] ( https://cpp4arduino.com/2018/10/26/why-cpp-programmers-stopped-using-null.html )
You can’t perform that action at this time.
0 commit comments