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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:14:20+00:00 2026-05-31T00:14:20+00:00

I’ve just read about mode_t that it basically stores the following information: 7 boolean

  • 0

I’ve just read about mode_t that it basically stores the following information:

  • 7 boolean values for the file type (S_IFREG, S_IFDIR, S_IFCHR, S_ISBLK, S_ISFIFO, S_ISLINK, S_ISSOCK)
  • 3*3 = 9 boolean values for the access permissons (read, write and execute for owner, group and others)

So it needs 16 bit = 2 bytes. I guess you could even have one bit less for the file type, as it has to be either a regular file, a directory, a character or block device, a socket, a symbolic link, or a pipe. Or do other file types exist?

So I’ve just checked the size of mode_t with

printf("Size: %d byte\n", sizeof(mode_t));

It uses 4 byte. Why does it use 4 byte? Is there any additional information I didn’t notice?

edit:
I’ve just found that mode_t is defined in ptypes.inc:

type mode_t = cuint32;

cuint32 is a 32 bits sized, unsigned integer and defined in ctypes.inc:

type cuint32 = LongWord;

Perhaps this helps for the answer.

  • 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-31T00:14:22+00:00Added an answer on May 31, 2026 at 12:14 am

    Let’s look at what a “dumb” compiler would do when given the following code:

    #include <stdio.h>
    #include <stdint.h>
    
    int main(int argc, char **argv) {
      uint16_t test1 = 0x1122;
      uint32_t test2 = 0x11223344;
      if (test1 & 0x0100)
        printf("yay1.\n");
      if (test2 & 0x00010000)
        printf("yay2.\n");
    }
    

    This seems like a likely use case for values of type mode_t, checking if a flag is set. Now we compile it with gcc -O0 and check the generated assembly:

    0000000000000000 <main>:
                ...
       f:   66 c7 45 fe 22 11       movw   $0x1122,-0x2(%rbp)
      15:   c7 45 f8 44 33 22 11    movl   $0x11223344,-0x8(%rbp)
      1c:   0f b7 45 fe             movzwl -0x2(%rbp),%eax  ; load test1 into %eax
      20:   25 00 01 00 00          and    $0x100,%eax
      25:   85 c0                   test   %eax,%eax
                ...
      33:   8b 45 f8                mov    -0x8(%rbp),%eax  ; load test2 into %eax
      36:   25 00 00 01 00          and    $0x10000,%eax
      3b:   85 c0                   test   %eax,%eax
                ...
    

    See how the special movzwl instruction is needed to load the 16-bit value? This is because it needs to be sign-extended to two additional bytes to fit in the register. Obviously this instruction is more complex than a simple mov. This might have a tiny impact on performance, and it might increase the executable size by some bytes, which by itself wouldn’t be too bad.

    However, if we consider that there would be no advantage in using a 16-bit value, because it would usually take up 32 bits of storage anyway due to alignment, it’s clear why the designers choose to use the native word size of the CPU here.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.