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 9037931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:21:40+00:00 2026-06-16T09:21:40+00:00

To determine the endianness of a system, I plan to store a multi-byte integer

  • 0

To determine the endianness of a system, I plan to store a multi-byte integer value in a variable and access the first byte via an unsigned char wrapped in a union; for example:

union{
    unsigned int val;
    unsigned char first_byte;
} test;

test.val = 1; /* stored in little-endian system as "0x01 0x00 0x00 0x00" */

if(test.first_byte == 1){
    printf("Little-endian system!");
}else{
    printf("Big-endian system!");
}

I want to make this test portable across platforms, but I’m not sure if the C99 standard guarantees that the unsigned int data type will be greater than one byte in size. Furthermore, since a “C byte” does not technically have to be 8-bits in size, I cannot use exact width integer types (e.g. uint8_t, uint16_t, etc.).

Are there any C data types guaranteed by the C99 standard to be at least two bytes in size?

P.S. Assuming an unsigned int is in fact greater than one byte, would my union behave as I’m expecting (with the variable first_byte accessing the first byte in variable val) across all C99 compatible platforms?

  • 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-06-16T09:21:42+00:00Added an answer on June 16, 2026 at 9:21 am

    Since int must have a range of at least 16 bits, int will meet your criterion on most practical systems. So would short (and long, and long long). If you want exactly 16 bits, you have to look to see whether int16_t and uint16_t are declared in <stdint.h>.

    If you are worried about systems where CHAR_BIT is greater than 8, then you have to work harder. If CHAR_BIT is 32, then only long long is guaranteed to hold two characters.


    What the C standard says about sizes of integer types

    In a comment, Richard J Ross III says:

    The standard says absolutely nothing about the size of an int except that it must be larger than or equal to short, so, for example, it could be 10 bits on some systems I’ve worked on.

    On the contrary, the C standard has specifications on the lower bounds on the ranges that must be supported by different types, and a system with 10-bit int would not be conformant C.

    Specifically, in ISO/IEC 9899:2011 §5.2.4.2.1 Sizes of integer types <limits.h>, it says:

    ¶1 The values given below shall be replaced by constant expressions suitable for use in #if
    preprocessing directives. Moreover, except for CHAR_BIT and MB_LEN_MAX, the
    following shall be replaced by expressions that have the same type as would an
    expression that is an object of the corresponding type converted according to the integer
    promotions. Their implementation-defined values shall be equal or greater in magnitude
    (absolute value) to those shown, with the same sign.

    — number of bits for smallest object that is not a bit-field (byte)
    CHAR_BIT 8

    […]

    — minimum value for an object of type short int

    SHRT_MIN -32767 // −(215 − 1)

    — maximum value for an object of type short int

    SHRT_MAX +32767 // 215 − 1

    — maximum value for an object of type unsigned short int

    USHRT_MAX 65535 // 216 − 1

    — minimum value for an object of type int

    INT_MIN -32767 // −(215 − 1)

    — maximum value for an object of type int

    INT_MAX +32767 // 215 − 1

    — maximum value for an object of type unsigned int

    UINT_MAX 65535 // 216 − 1

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

Sidebar

Related Questions

Write a program to determine whether a computer is big-endian or little-endian. bool endianness()
I'm trying to determine if the current system is 32 or 64 bit. And
How can I portably determine the maximum value of the pid_t type? There's no
How can I determine SelectedCell 's Value In DataGrid ? (WPF) My DataGrid has
Is there a safe, portable way to determine (during compile time) the endianness of
Possible Duplicate: Detecting endianness programmatically in a C++ program C Macro definition to determine
I'm curious if this function will determine endianness. The test is a bitmask that
How can i determine the value is changed in the select box without clicking
I'm trying to determine if my sqlite access to a database is thread-safe on
I am trying to determine how to configure access to a Web API controller

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.