Make sure Integer doesn't overflow

Hey together,

I have a integer variable that I publish to an MQTT broker as a life bit.
Since I want to let this run for basically forever, I want to make sure that the variable doesnt overflow.
How can I make sure that doesnt happen?

How I declared the variable:

int             MqttPayloadLifeBit  = 0;

How it's used:

    // Publish lifebit message
    mqttClient.beginMessage(MqttTopicPub, MqttPayloadPub.length(), MqttRetainedPub, MqttQosPub, MqttDupPub);
    mqttClient.print(MqttPayloadPub);
    mqttClient.endMessage();
    // Count life bit
    MqttPayloadLifeBit++;

Thank you so far!

An unsigned integer e.g. uint16_t does not overflow. It does, however, roll over through zero when full. An overflow usually causes a system crash of some sort. A rollover does not.

So like I'm used to it, thank you :smiley: