October 22, 2024
Chicago 12, Melborne City, USA
C++

Warning: Iteration 1 Invokes Undefined Behavior


I’m not seeing the issue.

typedef struct GeneralSensorParams_
{
    uint8_t     threshold;
    uint8_t     negativeThreshold;
    uint8_t     baselineThreshold;  
} GeneralSensorParams;  

typedef _ALIGNED_(64) struct GeneralNVParams_
{
    uint32_t checksumOffset;
    GeneralSystemParams   system;
    PerSensorBitFields    bitfields[10];
    GeneralSensorParams   sensor[1];
    uint8_t            checksum;
} GeneralNVParams;

GeneralNVParams const* G_pGeneralNVParams = NULL;

int main (void)
{
    for (uint8_t i = 0; i < 1; i++)
    {
        if (tempThreshold[i] > G_pGeneralNVParams->sensor[i].threshold)
        {
            reTrigger = 2;
        }
    }
}

FWIW, the compiler specifically flags the direct access member operator as the "issue", but I don’t understand why. Note: this example does not show it, but the threshold value IS init’d to a real value.

warning: iteration 1 invokes undefined behavior [-Waggressive-loop-optimizations]
  253 |                 if (tempThreshold[i] > G_pGeneralNVParams->sensor[i].threshold)
  |                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ 



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video