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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:08:25+00:00 2026-05-18T11:08:25+00:00

Is there a safe, portable way to determine (during compile time) the endianness of

  • 0

Is there a safe, portable way to determine (during compile time) the endianness of the platform that my program is being compiled on? I’m writing in C.

[EDIT]
Thanks for the answers, I decided to stick with the runtime solution!

  • 1 1 Answer
  • 1 View
  • 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-18T11:08:25+00:00Added an answer on May 18, 2026 at 11:08 am

    This is for compile time checking

    You could use information from the boost header file endian.hpp, which covers many platforms.

    edit for runtime checking

    bool isLittleEndian()
    {
        short int number = 0x1;
        char *numPtr = (char*)&number;
        return (numPtr[0] == 1);
    }
    

    Create an integer, and read its first byte (least significant byte). If that byte is 1, then the system is little endian, otherwise it’s big endian.

    edit Thinking about it

    Yes you could run into a potential issue in some platforms (can’t think of any) where sizeof(char) == sizeof(short int). You could use fixed width multi-byte integral types available in <stdint.h>, or if your platform doesn’t have it, again you could adapt a boost header for your use: stdint.hpp

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

Sidebar

Related Questions

Is there a safe way to determine that a device is of a particular
Is there any way to play progressive videos that is not safe for streaming
I have an external library that takes an IntPtr. Is there any safe way
Is there a safe way to change the priority of an NSOperation that is
Is there any safe crypting algorithm that you can I can use this way?
Is there any safe and standard compliant way to treat a C style array
Is there a way I can ask Visual source safe to get all the
Is there a way to export files/folders from Source Safe? (i.e. getting rid of
Is there any primitive data type that it's safe to not initialize? How about
Is there any way to check if it is safe to delete record from

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.