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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:12:01+00:00 2026-06-10T23:12:01+00:00

I know that function arguments are padded to target word size, but with what?

  • 0

I know that function arguments are padded to target word size, but with what?

Specifically in the context of the x86 Linux GNU toolchain, what do these functions return?

int iMysteryMeat(short x)
{
    return *((int *)&x);
}
unsigned uMysteryMeat(unsigned short x)
{
    return *((unsigned *)&x);
}

The question is whether, when hand-coding a function in assembly, it is necessary to sterilze “small” arguments by masking or sign-extending them before using them in “large” contexts (andl, imull).

I’d also be interested whether there are any more general or cross-platform standards for this case.

  • 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-10T23:12:03+00:00Added an answer on June 10, 2026 at 11:12 pm

    This depends on the ABI. The ABI needs to specify the choice that small arguments are extended by the caller, or by the callee (and how). Unfortunately, this part of the ABI is often underspecified, leading to different choices by different compilers. So to prevent incompatibility between code compiled with different legacy compilers, most modern compilers (I know in particular about gcc on i386) err on the side of caution and do both.

    int a(short x) {
      return x;
    }
    int b(int x);
    int c(short x) {
      b(x);
    }
    
    gcc -m32 -O3 -S tmp.c -o tmp.s
    
    _a:
    pushl   %ebp
    movl    %esp, %ebp
    movswl  8(%ebp),%eax
    leave
    ret
    
    _c:
    pushl   %ebp
    movl    %esp, %ebp
    movswl  8(%ebp),%eax
    movl    %eax, 8(%ebp)
    leave
    jmp _b
    

    Note that a does not assume any extension rule about its argument, but extends it itself. Similarly, c makes sure to extend its argument before passing it to b (via a tail call).

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

Sidebar

Related Questions

I know, type checking function arguments is generally frowned upon in Python, but I
I know arguments.length method , but this returns the number of arguments the function
I know that a function pointer stores the address of a function. int fun(int
Occasionally I will know that there is a .NET Framework function that returns a
In jquery when I run: $('li').each(some-function(i){}); The IDE seems to know that some-function is
I know that if I am inside some function foo() which is called somewhere
I know that when passing an object by value to a function, the move
I know that it's OK for a pure virtual function to have an implementation.
I know that variables allocated on that stack of a function become inaccessible when
I know that javascript, for example supports functions inside of functions, like so: function

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.