Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective C(++) Insanity -- simple assignement to a single float variable results in {{{CRAZY}}} values in another variable
    primarykey
    data
    text
    <p>memberA is defined in the header of ClassA.</p> <p>memberB is defined in the header of ClassB.</p> <p>ClassB is a subclass of ClassA</p> <p>Inside an instance of ClassB, setting memberA via simple assignment:</p> <pre><code>memberA = 0.05 </code></pre> <p>...also changes memberB, but to a crazy number -- 1028443341. Additionally, assigning 0.05 to memberA results in memberA showing up in the debugger as 5.33083531e-38.</p> <p>Both variables are floats, neither is a pointer. I'm almost certianly making some noob mistake, but I don't have any clue what it might be. What sort of screw-up might make it so assigning a value to one variable results in crazy values appearing in two variables?</p> <p>********************* Edit **********************</p> <p>I narrowed the problem down to some "trickiness" I'd done in order to get C++ member variables:</p> <p>Thanks for all the thoughts folks. It's dangerous letting a noob like me at this low-level language stuff! Here's where the problem was:</p> <pre><code>@interface LoopyPulser : NSObject{ float _pulseRate; UInt32 tickInterval; UInt32 step; InMemoryAudioFile * audioFilePlayer; #ifdef __cplusplus ADSR* env; StkFrames* audioFrames; # endif Pattern * pattern; float loopLengthRatio; float volume; } </code></pre> <p>I read about this #ifdef __cplusplus business somewhere else on SO, as a way to have C++ imports in header files which are then imported by Obj-C files. Seems to me now that this is a terrible idea, and most likely the cause of my crazy bug. If I remove the member vars inside the #ifdef __cplusplus, the insanity goes away. </p> <p>So what's the best way to have C++ member variables in Obj-C++? Can I use ids maybe?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload