Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 21, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 21, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 21, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 21, 2025

      The best smart glasses unveiled at I/O 2025 weren’t made by Google

      May 21, 2025

      Google’s upcoming AI smart glasses may finally convince me to switch to a pair full-time

      May 21, 2025

      I tried Samsung’s Project Moohan XR headset at I/O 2025 – and couldn’t help but smile

      May 21, 2025

      Is Google’s $250-per-month AI subscription plan worth it? Here’s what’s included

      May 21, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      IOT and API Integration With MuleSoft: The Road to Seamless Connectivity

      May 21, 2025
      Recent

      IOT and API Integration With MuleSoft: The Road to Seamless Connectivity

      May 21, 2025

      Celebrating GAAD by Committing to Universal Design: Low Physical Effort

      May 21, 2025

      Celebrating GAAD by Committing to Universal Design: Flexibility in Use

      May 21, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft open-sources Windows Subsystem for Linux at Build 2025

      May 21, 2025
      Recent

      Microsoft open-sources Windows Subsystem for Linux at Build 2025

      May 21, 2025

      Microsoft Brings Grok 3 AI to Azure with Guardrails and Enterprise Controls

      May 21, 2025

      You won’t have to pay a fee to publish apps to Microsoft Store

      May 21, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: A Type of Alias

    CodeSOD: A Type of Alias

    June 3, 2024

    Joe inherited some C code that left him scratching his head.

    It doesn’t start too badly:

    typedef unsigned char byte;
    typedef unsigned short word;

    This aliases two built-in types (unsigned char and unsigned short) to byte and word, respectively. This isn’t uncommon, using typedefs to give types more convenient or descriptive names is generally a good practice. The typedef is just an alias at compile time, so you’re not really changing anything, just creating an easy to reference name.

    As always, it’s worth noting that short has a minimum size, but no maximum size defined in the spec. So assuming that a word is two bytes is potentially a mistake.

    But that’s not the WTF. The WTF is the next two lines, so here’s the whole snippet, for context:

    typedef unsigned char byte;
    typedef unsigned short word;
    #define byte unsigned char
    #define word unsigned short

    This creates a preprocessor macro that will replace all occurrences of byte with unsigned char, and all occurrences of word with unsigned short. This will run before compilation, and essentially be a find/replace. This means that by the time the compiler gets the code, there will be no bytes or words. So the typedef doesn’t matter- the compiler will never see the alias used.

    This code isn’t the worst abuse we’ve seen in C, by far, but it still leaves me scratching my head, trying to understand how we got here. I could understand it better if these four lines weren’t all together. One header doing a typedef, and another header doing a #define would be bad, but that’s just the life of a C programmer, as you pull together modules written by different people across different years. I could understand having that happen. But right next to each other?

    [Advertisement]
    Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleLWiAI Podcast #169 – Google’s Search Errors, OpenAI news & DRAMA, new leaderboards
    Next Article Web Application VS JMeter Reports differences

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 21, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-48205 – TYPO3 sr_feuser_register Insecure Direct Object Reference

    May 21, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Build generative AI applications on Amazon Bedrock — the secure, compliant, and responsible foundation

    Development

    Dynamic Tanh DyT: A Simplified Alternative to Normalization in Transformers

    Machine Learning

    CVE-2025-37776 – Linux ksmbd Use-After-Free Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Meta, Facebook, and Instagram AI is coming for EU data — Here’s what you need to know (and how to opt out)

    News & Updates

    Highlights

    Development

    This AI Paper from Cohere Enhances Language Model Stability with Automated Detection of Under-trained Tokens in LLMs

    May 14, 2024

    Tokenization is essential in computational linguistics, particularly in the training and functionality of large language…

    Optimizing LLM Reasoning: Balancing Internal Knowledge and Tool Use with SMART

    February 25, 2025

    If COBOL is so problematic, why does the US government still use it?

    February 21, 2025

    Chinese AGI Startup ‘StepFun’ Developed ‘Step-2’: A New Trillion-Parameter MoE Architecture Model Ranking 5th on Livebench

    November 21, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.