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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:25:48+00:00 2026-06-17T04:25:48+00:00

I have a group of functions that are all declared static and fastcall .

  • 0

I have a group of functions that are all declared static and fastcall. Most of them make use of a pointer to a struct that serves more or less the role of this in C++. Some of the functions don’t need anything in the struct, but for uniformity sake I want to pass them the pointer anyway. Will the compiler notice that the argument is not used and omit allocating a register to it?

  • 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-17T04:25:49+00:00Added an answer on June 17, 2026 at 4:25 am

    I wrote this nonsense program to test this. It’s got some nonsense code in the function, and calls it several times because otherwise the compiler just inlined the whole function call making the test useless. (It’s a strange mix of C and C++ i know…. stupid code, but still works to demonstrate the issue)

    #include <stdio.h>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    
    struct demo
    {
        int a;
        char ch;
    };
    
    static  void __fastcall func(struct demo* d)
    {
        for(int i = 0; i < 100; i++) {
        std::vector<int> a;
        std::sort(begin(a), end(a));
        printf("THis is a test");
        printf("Hello world\n");
        }
    }
    
    int main()
    {
      //  void*p = (void*)&func;
        struct demo d;
        func(&d);
        func(&d);
        func(&d);
        func(&d);
        func(&d);
        func(&d);
        func(&d);
        //printf((const char*)p);
    }
    

    As written there the function calls compile to this :-

        func(&d);
    00F61096  call        func (0F61000h)  
        func(&d);
    00F6109B  call        func (0F61000h)  
        func(&d);
    00F610A0  call        func (0F61000h)  
        func(&d);
    00F610A5  call        func (0F61000h)  
        func(&d);
    00F610AA  call        func (0F61000h)  
        func(&d);
    00F610AF  call        func (0F61000h)  
        func(&d);
    00F610B4  call        func (0F61000h)  
    

    Which shows that the compiler will indeed omit the parameter if it’s not used.
    However if I uncomment the two lines there to take the address of the function then things change, it instead generated this :-

    00C71099  lea         ecx,[esp]  
    00C7109C  call        func (0C71000h)  
        func(&d);
    00C710A1  lea         ecx,[esp]  
    00C710A4  call        func (0C71000h)  
        func(&d);
    00C710A9  lea         ecx,[esp]  
    00C710AC  call        func (0C71000h)  
        func(&d);
    00C710B1  lea         ecx,[esp]  
    00C710B4  call        func (0C71000h) 
    

    Where it DOES send the pointer.

    My assumption is that in the first case the compiler is able to prove that if it generated a custom calling convention to the function that there cannot possibly be any user visible effects but in the second case where you take a pointer to the function, the function could be called from another separately compiled module which has no way to know if the parameter is needed or not. Although in this case it wouldn’t matter if the register was set or not, in general the compiler needs to stickl to the exact calling pattern so I assume that it generated the most general code and won’t use custom calling conventions if it can’t prove that it can see all the code that could call the function.

    Anyway, to answer the question, no the compiler will not always pass unused parameters in a register but I certainly wouldn’t write any code that depends on any specific behavior here as changing unrelated code elsewhere (taking the address of the function), changed that behavior and there is nothing guaranteed by any standard that I can see.

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

Sidebar

Related Questions

I have a group of functions that use Sub-Range types for their input parameter.
I have a series of functions that are all designed to do the same
I have a group of numeric functions in Clojure that I want to validate
I have a group of model peer classes that should all have the same
I have group of check boxes named as modules[]. I want to access them
I have a group of links that I call fancybox on with the arrows
I have a group of buttons that should act like toggle buttons, but also
I have a group of 4 divs and I'm looking to use jQuery to
I have a Firefox extension that implements a bunch of little functions that can
I'm building an application that needs to use the Linux group keyring to share

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.