Unchecked

Solidity

परिभाषा

Unchecked block arithmetic operations को overflow/underflow checks के बिना execute करता है। Solidity 0.8.0+ में automatic checks हैं, लेकिन unchecked gas save कर सकता है जब आप certain हैं कि overflow नहीं हो सकता। सावधानी से use करें।

English version

The unchecked block executes arithmetic operations without overflow/underflow checks. Solidity 0.8.0+ has automatic checks, but unchecked can save gas when you are certain overflow cannot occur. Use with caution.

Code Example

function increment(uint256 x) public pure returns (uint256) {
    // Avec vérification (par défaut 0.8.0+)
    return x + 1; // Revert si overflow
}

function incrementUnchecked(uint256 x) public pure returns (uint256) {
    unchecked {
        return x + 1; // Pas de vérification, wraparound si overflow
    }
}

// Cas d'usage : compteur jamais overflow
uint256 counter;
function increment() public {
    unchecked { counter++; } // Économie de gas
}

संबंधित शब्द

Solingo पर इस concept को practice करें

Unchecked को interactive exercises और integrated IDE के साथ master करें।

मुफ्त में शुरू करें