# C++ Compiler Initializer Issue?

**URL:** <https://community.particle.io/t/c-compiler-initializer-issue/37310>\
**Category:** Troubleshooting\
**Created:** [November 7, 2017, 5:33pm UTC](https://community.particle.io/t/c-compiler-initializer-issue/37310 "2017-11-07T17:33:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarkZ](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@MarkZ](https://community.particle.io/u/MarkZ)\
**Post date:** [November 7, 2017, 5:33pm UTC](https://community.particle.io/t/c-compiler-initializer-issue/37310/1 "2017-11-07T17:33:34Z")

</div>

I've been using the DS18B20 library and had real flakiness. Sometimes the temperature was way too high. I finally tracked it down today after a few hours and it seems to be a value not initializing. I can't figure out how this could be happening. My code is the library DS18B20 and OneWire. Here's the relevant issue:

Here's the DS18B20 constructor:

> DS18B20::DS18B20(uint16\_t pin, bool singleDrop) : \_singleDrop(singleDrop){  
> ds = new OneWire(pin);  
> }

Here's how I use it:

> \_Sensor = new DS18B20(\_Pin, true);

And here's my test code

> DS18B20::DS18B20(uint16\_t pin, bool singleDrop) : \_singleDrop(singleDrop){  
> ds = new OneWire(pin);  
> Serial.println("Byte value2: " + String(type\_s));  
> }

This prints: "Byte value2: 15" to the serial port.

> DS18B20::DS18B20(uint16\_t pin, bool singleDrop) : \_singleDrop(singleDrop), type\_s(0) {  
> ds = new OneWire(pin);  
> Serial.println("Byte value2: " + String(type\_s));  
> }

This prints: "Byte value2: 0" to the serial port.

Can anyone explain what's going on here? Is there any created assembly code I can look at to diagnose this or is there a way to set a breakpoint when something writes to this address? The type\_s byte variable is just a member of the DS18B20 object and should be initialized to 0.

Or, am I just dumb and missing something obvious?

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![BulldogLowell](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bulldoglowell/32/4305_2.png) [@BulldogLowell](https://community.particle.io/u/BulldogLowell)\
**Post date:** [November 7, 2017, 6:00pm UTC](https://community.particle.io/t/c-compiler-initializer-issue/37310/2 "2017-11-07T18:00:57Z")

</div>

> [@MarkZ](#):
>
> DS18B20

So, you are trying to modify the library in the IDE?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [November 7, 2017, 6:04pm UTC](https://community.particle.io/t/c-compiler-initializer-issue/37310/3 "2017-11-07T18:04:08Z")

</div>

Since the dynamic object will just be created on the heap its fields won’t be initialised unless done explicitly in code.  
But the “random” value after instantiation shouldn’t matter when you perform a sensor search (`DS18B20::search()`) to set the correct type.

On the other hand, if you already know your type, adding a way to set the type from outside, may be a good addition.

PRs welcome 👍

> **[eliteio/DS18B20](https://github.com/eliteio/DS18B20)**
>
> DS18B20 - Dallas One-Wire temp sensor DS18XXX Particle Photon

_Update:_  
I just looked at the most recent version (0.1.6) and in that I had removed the `type_s` field completely as it’s redundant anyway - the sensor ID (`addr[]`) provides all relevant data.

---

<div class="post-metadata">

**Author:** ![MarkZ](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@MarkZ](https://community.particle.io/u/MarkZ)\
**Post date:** [November 7, 2017, 8:01pm UTC](https://community.particle.io/t/c-compiler-initializer-issue/37310/4 "2017-11-07T20:01:28Z")

</div>

> [@ScruffR](#):
>
> Since the dynamic object will just be created on the heap its fields won't be initialised unless done explicitly in code.

Wow, it's been too long since I programmed in C++.

Thanks,  
Mark
