# microsoft/gsl

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/microsoft-gsl).**

6,693 stars · 766 forks · C++ · NOASSERTION

## Links

- GitHub: https://github.com/microsoft/GSL
- awesome-repositories: https://awesome-repositories.com/repository/microsoft-gsl.md

## Description

GSL is a Guidelines Support Library for C++ that provides a set of types and functions designed to implement the C++ Core Guidelines. It functions as a framework for improving code safety and portability across different platforms.

The library provides a contract-based programming model to verify program invariants through precondition and postcondition assertions. It includes specialized wrappers for null-pointer safety and bounds-checked memory views to prevent buffer overflows and invalid memory access.

The project also covers safe integer conversion to prevent data truncation and provides utilities for managing zero-terminated strings with various character encodings. Additionally, it includes mechanisms for resource management to ensure cleanup functions execute during object destruction.

## Tags

### Programming Languages & Runtimes

- [C++ Guidelines Support Libraries](https://awesome-repositories.com/f/programming-languages-runtimes/c-guidelines-support-libraries.md) — Provides a set of types and functions for implementing the C++ Core Guidelines to improve code safety and portability.
- [Portable C++ Subsets](https://awesome-repositories.com/f/programming-languages-runtimes/c-and-c-cross-compilation/portable-c-subsets.md) — Provides standardized types and functions to maintain consistent behavior and safety across different platforms.
- [Checked Narrowing Conversions](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-definitions/variable-type-declarations/type-narrowing/checked-narrowing-conversions.md) — Implements safe integer narrowing that triggers exceptions if the original value is truncated during conversion. ([source](https://github.com/microsoft/gsl#readme))
- [Type Safety](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-safety.md) — Handles narrow value conversions and character encodings to prevent data truncation and encoding errors.
- [Safe Integer Narrowing Utilities](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/data-structure-type-helpers/data-type-utilities/integer-conversion-utilities/safe-integer-narrowing-utilities.md) — Provides a utility for converting values to smaller types with exception triggers upon truncation.

### Part of an Awesome List

- [Contract-Based Libraries](https://awesome-repositories.com/f/awesome-lists/devtools/contract-programming/contract-based-libraries.md) — Provides a framework for verifying program invariants using precondition and postcondition assertions.
- [Standard Library Extensions](https://awesome-repositories.com/f/awesome-lists/devtools/standard-library-extensions.md) — Guidelines Support Library implementation.

### Development Tools & Productivity

- [Null-Safety Pointer Types](https://awesome-repositories.com/f/development-tools-productivity/dead-code-elimination/null-safety-enforcement/null-safety-pointer-types.md) — Provides a specialized pointer type that ensures memory addresses are valid and non-null.
- [Memory Safety Protections](https://awesome-repositories.com/f/development-tools-productivity/memory-buffering-utilities/memory-safety-protections.md) — Prevents buffer overflows and invalid memory access using bounds-checked views and pointer constraints.

### Operating Systems & Systems Programming

- [Non-Null Pointer Wrappers](https://awesome-repositories.com/f/operating-systems-systems-programming/non-null-pointer-wrappers.md) — Provides specialized pointer types that ensure a pointer always holds a valid value and never refers to null. ([source](https://github.com/microsoft/gsl#readme))
- [C++ Resource Management](https://awesome-repositories.com/f/operating-systems-systems-programming/c-resource-management.md) — Ensures proper cleanup of system resources and executes final actions during object destruction.
- [Resource Cleanup Utilities](https://awesome-repositories.com/f/operating-systems-systems-programming/resource-cleanup-utilities.md) — Provides mechanisms to execute specific cleanup functions during object destruction to ensure system resources are released properly. ([source](https://github.com/microsoft/gsl#readme))

### Security & Cryptography

- [Runtime Bounds Checking](https://awesome-repositories.com/f/security-cryptography/memory-bounds-checking/runtime-bounds-checking.md) — Implements a specialized memory access wrapper that prevents buffer overflow errors through strict runtime bounds checking.

### Software Engineering & Architecture

- [Memory Spans](https://awesome-repositories.com/f/software-engineering-architecture/block-based-data-models/data-block-memory-management/contiguous-memory-buffers/memory-spans.md) — Provides bounds-checked memory views to prevent buffer overflows and invalid memory access. ([source](https://github.com/microsoft/gsl#readme))
- [Coding Style Guidelines](https://awesome-repositories.com/f/software-engineering-architecture/coding-style-guidelines.md) — Implements a set of uniform types and functions to apply C++ Core Guidelines for improved safety and portability. ([source](https://github.com/microsoft/gsl#readme))
- [Runtime Invariant Verifications](https://awesome-repositories.com/f/software-engineering-architecture/runtime-invariant-verifications.md) — Implements a contract-based programming model using precondition and postcondition assertions to verify program invariants. ([source](https://github.com/microsoft/gsl#readme))

### Testing & Quality Assurance

- [Logic Verification Frameworks](https://awesome-repositories.com/f/testing-quality-assurance/logic-verification-frameworks.md) — Uses preconditions and postconditions to verify program invariants and stop execution upon logic failure.
