TZPike05
TZPike05

Reputation: 1188

Assertion Failed in C++ questions

Running into an issue with some code I'm working on. This code is being run on a linux-based system and the error I receive is the following: /root/cvswork/pci_sync_card/Code/SSBSupport/src/CRCWbHfChannel/CRCWbHfMSBSimulator.cpp:447: virtual void CCRCWbHfMSBSimulator::Process(): Assertion 'pcBasebandOutput' failed.

I've tried stepping through this code to figure out why this is failing and I can't seem to figure it out. Unfortunately I have too many files to really share the code on here (stepping through the pcBasebandOutput assignment takes quite some time). I understand this is a more complex issue than can really be asked about. My primary questions are these:

  1. Is my assert(pcBasebandOutput); line of code necessary? I only ask because when running this code on Visual Studio, the results from my program were desirable.
  2. When it is evaluating my pcBasebandOutput variable, why would it evaluate it as false? Is this saying that no value is actually assigned to pcBasebandOutput? Or that a value may be assigned to it, but it is not of the right type (pointer to a struct of two variables, both of which are doubles)?

Thanks!

Upvotes: 0

Views: 206

Answers (2)

marcinj
marcinj

Reputation: 49986

  1. Only you can know that

  2. What is the type of pcBasebandOutput ? Maybe it is not properly initialized?

assert primary purpose is to allow your IDE to enter debuging session in the place where assert has hit. From there you can read all variables and see callstack/threads. Other solution (than using debugger) is to add lots of logging, which in threaded environments can cause problems on its own (logging is quite slow).

Upvotes: 1

Andrew
Andrew

Reputation: 24846

assert checks a logical condition. Assertation fails if the condition is false. So writing assert(cond) is logically the same as writing:

if (!cond)
{
    assert(false);
}

I don't suggest you to remove assert from the code, because it is a guard telling you that something went not the way it's intended to go. And it's not a god idea just to ignore that, because it may shoot you in a leg later

Upvotes: 1

Related Questions