☠️
smadi0x86 Playground
  • 💀Welcome to smadi0x86 Playground
    • 🍷Resources
    • 🚬Projects
    • 🎓Certifications
    • 📌Pinned
    • ❓Questions
    • 📞Contact
  • 🏞️Cloud Native
    • Docker
      • Quick Reference
      • Introduction
      • Containers
      • Images
      • Storage & Volumes
      • Security
      • Cheatsheet
    • Git
    • Serverless Framework
    • YAML
  • 🔨Software Engineering
    • System Design
    • Environment Variables
    • JSON Web Tokens
  • 👾Architecture
    • C Language
      • Introduction
      • Calling Conventions
      • GCC Compilation
      • Libraries & Linking
      • I/O
      • Files
      • Pointers
      • Dynamic Memory Allocation
      • Data Types
      • Strings Manipulation
      • Bit Manipulation
      • Pre-processors
      • Macros
      • Type Qualifiers
    • C/C++ Build Systems
      • Fundamentals for Linking
      • Symbolic Linking
      • Cross-Platform Compilation
      • CMake for Building and Linking
      • Shared Libraries
      • Dynamic Linking and Dependency Management
    • Operating Systems
      • OS & Architecture
      • Processes
      • CPU Scheduling
      • Memory Management
  • 🛩️Cyber Warfare
    • Flight Physics
    • Communication
      • PWM & PPM
      • MAVLink
  • 🏴‍☠️Offensive Security
    • Active Directory
      • Introduction
    • Web Attacks
      • Server Side
        • OS Command Injection
        • Information Disclosure
        • Directory Traversal
        • Business Logic
        • Authentication
        • File Upload
        • SSRF
      • Client Side
        • CSRF
        • XSS
    • Recon
      • Active
        • Host discovery
        • Nmap
        • Mass Scan
      • Passive
        • Metadata
      • Web Applications
        • Discovery
        • Subdomains & Directories
        • SSL Certs
        • CMS
        • WAF Detection
      • Firewall Evasion
  • Binary Exploitation
    • Stack Smashing
      • x86
      • x86_64
    • pwntools
      • Processes and Communication
      • Logging and Context
      • Cyclic
      • Packing
      • ELF
      • ROP
  • 😈Advanced Persistent Threat
    • C2
      • Sliver
    • Malware
      • Windows Internals
        • PEB
      • Academy
        • Basics
      • Sektor7
        • Essentials
  • 💌Certifications
    • AWS Certified Cloud Practitioner (CLF-C01)
      • Cloud Foundations
      • Domain 1: Cloud Concepts
      • Domain 2: Security and Compliance
      • Domain 3: Technology
      • Domain 4: Billing and Pricing
    • AWS Certified Solutions Architect - Associate (SAA-C03)
      • Foundation
    • Certified Kubernetes Administrator (CKA)
      • Core Concepts
      • Scheduling
      • Logging & Monitoring
      • Application Lifecycle Management
      • Cluster Maintenance
      • Security
      • Storage
      • Networking
      • Design Kubernetes Cluster
      • Kubernetes The Kubeadm Way
      • Troubleshooting
      • JSONPATH
      • Lightning Lab
      • Mock Exams
      • Killer Shell
    • Certified Kubernetes Security (CKS)
      • Foundation
      • Cluster Setup
      • Cluster Hardening
      • Supply Chain Security
      • Runtime Security
      • System Hardening
      • Killer Shell
    • (KGAC-101) Kong Gateway Foundations
      • Introduction to APIs and API Management
      • Introduction to Kong Gateway
      • Getting Started with Kong Enterprise
      • Getting Started with Kong Konnect
      • Introduction to Kong Plugins
  • 📜Blog Posts
    • Modern Solutions For Preventing Ransomware Attacks
Powered by GitBook
On this page
  • const
  • Volatile
  • Storage classes
  • Auto storage class
  • External variables
  • Static variables
  • Register
  1. Architecture
  2. C Language

Type Qualifiers

const

Means the variable will not be changed by the program.

 const int z = 10;

Volatile

Volatile means that the variable will change its value so tells the compiler to suppress various kinds of optimizations e.g: caching.

Only three types if variables should use volatile:

  • Memory-mapped peripheral registers.

  • Global variables modified by an interrupt service routine.

  • Global variables accessed by multiple tasks within a multi-threaded application.

volatile int z; 
volatile int *z;

Storage classes

Storage classes are used to describe the features of a variable / function.

Include the scope, visibility and life-time.

It helps up to trace the existence of a particular variable during the runtime of a program.

The lifetime of a variable is the time period during which variable exist in the memory.

The scope is where the variable can be referenced in a program.

A variables visibility or linkage determines for a multiple-source-file program whether the identifier is known only in the current source or in any source file with proper declarations.

C provides 4 storage classes:

  1. auto.

  2. register.

  3. extern.

  4. static.

The 4 classes can be split into 2 storage duration:

1. Automatic storage duration.

2. Static storage duration.

Auto storage class

Created when the block in which they are defined is entered, exits while the block is active, destroyed when the block is exited.

All local variables have auto storage duration by default.

Its better not to use auto as a storage-class specifier in c/c++.

 auto int var;

External variables

Functions contained in separate files can communicate through external variables, an extension to the concept of global variable.

A global var can be accessed and changed by other modules (files).

In the module that wants to access the external variable the data type is preceded with the key word extern in the declaration, tells the compiler that a globally defined variable from another file is to be accessed.

Example:

We have a var called moveNumber to access it in other functions we can define it as a global var outside any function:

 int moveNumber = 0;

To access this var from another file use:

 extern int moveNumber;

Static variables

We might want to define a var that is global but not external.

To do this we use a static variable definition.

If the below declaration is made outside any function it makes the value of the variable accessible from any subsequence pointed in the file in which the definition appears and not functions contained in other files.

 static int moveNumber = 0;

Register

We can store variables of any kind in CPU registers as well which is much faster than RAM.

This should be used only or variables that require quick access.

It is the compilers choice to put it in a register or not.

It might be stored in a register depending on hardware and implementation restrictions.

The max variable size is equal to the register size.

The variable life-time is within the block.

We cant obtain the address of a register variable using a pointer, there is no memory address

 register int x;
PreviousMacrosNextC/C++ Build Systems
👾