Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7591143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:34:50+00:00 2026-05-30T20:34:50+00:00

I just read an excellent post, Portable Fixed-Width Integers in C , everything makes

  • 0

I just read an excellent post, Portable Fixed-Width Integers in C, everything makes perfect sense till the almost the end, I am wondering what does the following paragraph means:

Of course, if you don’t have a C99-compliant compiler yet you’ll still have to write your own set of typedefs, using compiler-specific knowledge of the char, short, and long primitive widths. I recommend putting these typedefs in a header file of your own design and adding the anonymous union declaration shown in Listing 2 to a linked source module to check their sizes; that is, to gently “remind” whomever might someday have the task of porting your code.

static union
{
    char   int8_t_incorrect[sizeof(  int8_t) == 1];
    char  uint8_t_incorrect[sizeof( uint8_t) == 1];
    char  int16_t_incorrect[sizeof( int16_t) == 2];
    char uint16_t_incorrect[sizeof(uint16_t) == 2];
    char  int32_t_incorrect[sizeof( int32_t) == 4];
    char uint32_t_incorrect[sizeof(uint32_t) == 4];
};

Listing 2. This anonymous union allows a compiler to detect and report typedef errors

I experimented a small program:

typedef unsigned char  int8_t;
typedef unsigned short int16_t;

union u {
    char int8_incorrect[sizeof(int8_t)==1];
    char int16_incorrect[sizeof(int16_t)==2];
};


int main() {
    return 0;
}

There is no issue going through compiler. I changed int8_t into the following:

typedef unsigned int  int8_t;

There is no issue either.

Basically I missed the point why this example code can detect error.

Could you clarify what I missed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:34:52+00:00Added an answer on May 30, 2026 at 8:34 pm

    If you compile with gcc add -std=c89 -pedantic or -std=c99 pedantic to your gcc compile options to get the warning with this typedef and the union type:

    typedef unsigned int  int8_t;
    

    For this typedef:

    typedef unsigned char int8_t;
    

    it is normal you don’t get any warning, as the trick is to check the size of type, not wether it is a signed or unsigned type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just read a post mentioning full text search in SQL. I was just
I just read this post about why new-line warnings exist, but to be honest
I read this excellent article and it make sense: Java is strictly pass by
I just read this post about adding buttons with a loop programmatically . I
I just read this blog post about a recipe to lazily initialize an object
I just read secretGeek 's fun post on 8 ways to be a better
I just read a blog post that explains MVC with a banking analogy. I
I just read http://olstrans.sourceforge.net/release/OLS2000-ext3/OLS2000-ext3.html which is an excellent review of the design issues used
Just read a post about MVC best practices . Couple parts of the post
I just read up on a performance of LINQ, and there is a HUGE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.