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

  • Home
  • SEARCH
  • 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 6338719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:30:09+00:00 2026-05-24T19:30:09+00:00

As in, say my header file is: class A { void Complicated(); } And

  • 0

As in, say my header file is:

class A
{
    void Complicated();
}

And my source file

void A::Complicated()
{
    ...really long function...
}

Can I split the source file into

void DoInitialStuff(pass necessary vars by ref or value)
{
    ...
}
void HandleCaseA(pass necessary vars by ref or value)
{
    ...
}
void HandleCaseB(pass necessary vars by ref or value)
{
    ...
}
void FinishUp(pass necessary vars by ref or value)
{
    ...
}
void A::Complicated()
{
    ...
    DoInitialStuff(...);
    switch ...
        HandleCaseA(...)
        HandleCaseB(...)
    ...
    FinishUp(...)
}

Entirely for readability and without any fear of impact in terms of performance?

  • 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-24T19:30:09+00:00Added an answer on May 24, 2026 at 7:30 pm

    You should mark the functions static so that the compiler know they are local to that translation unit.

    Without static the compiler cannot assume (barring LTO / WPA) that the function is only called once, so is less likely to inline it.

    Demonstration using the LLVM Try Out page.

    That said, code for readability first, micro-optimizations (and such tweaking is a micro-optimization) should only come after performance measures.


    Example:

    #include <cstdio>
    
    static void foo(int i) {
      int m = i % 3;
      printf("%d %d", i, m);
    }
    
    int main(int argc, char* argv[]) {
      for (int i = 0; i != argc; ++i) {
        foo(i);
      }
    }
    

    Produces with static:

    ; ModuleID = '/tmp/webcompile/_27689_0.bc'
    target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
    target triple = "x86_64-unknown-linux-gnu"
    
    @.str = private constant [6 x i8] c"%d %d\00"     ; <[6 x i8]*> [#uses=1]
    
    define i32 @main(i32 %argc, i8** nocapture %argv) nounwind {
    entry:
      %cmp4 = icmp eq i32 %argc, 0                    ; <i1> [#uses=1]
      br i1 %cmp4, label %for.end, label %for.body
    
    for.body:                                         ; preds = %for.body, %entry
      %0 = phi i32 [ %inc, %for.body ], [ 0, %entry ] ; <i32> [#uses=3]
      %rem.i = srem i32 %0, 3                         ; <i32> [#uses=1]
      %call.i = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %rem.i) nounwind ; <i32> [#uses=0]
      %inc = add nsw i32 %0, 1                        ; <i32> [#uses=2]
      %exitcond = icmp eq i32 %inc, %argc             ; <i1> [#uses=1]
      br i1 %exitcond, label %for.end, label %for.body
    
    for.end:                                          ; preds = %for.body, %entry
      ret i32 0
    }
    
    declare i32 @printf(i8* nocapture, ...) nounwind
    

    Without static:

    ; ModuleID = '/tmp/webcompile/_27859_0.bc'
    target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
    target triple = "x86_64-unknown-linux-gnu"
    
    @.str = private constant [6 x i8] c"%d %d\00"     ; <[6 x i8]*> [#uses=1]
    
    define void @foo(int)(i32 %i) nounwind {
    entry:
      %rem = srem i32 %i, 3                           ; <i32> [#uses=1]
      %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str, i64 0, i64 0), i32 %i, i32 %rem) ; <i32> [#uses=0]
      ret void
    }
    
    declare i32 @printf(i8* nocapture, ...) nounwind
    
    define i32 @main(i32 %argc, i8** nocapture %argv) nounwind {
    entry:
      %cmp4 = icmp eq i32 %argc, 0                    ; <i1> [#uses=1]
      br i1 %cmp4, label %for.end, label %for.body
    
    for.body:                                         ; preds = %for.body, %entry
      %0 = phi i32 [ %inc, %for.body ], [ 0, %entry ] ; <i32> [#uses=3]
      %rem.i = srem i32 %0, 3                         ; <i32> [#uses=1]
      %call.i = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %rem.i) nounwind ; <i32> [#uses=0]
      %inc = add nsw i32 %0, 1                        ; <i32> [#uses=2]
      %exitcond = icmp eq i32 %inc, %argc             ; <i1> [#uses=1]
      br i1 %exitcond, label %for.end, label %for.body
    
    for.end:                                          ; preds = %for.body, %entry
      ret i32 0
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a function, let's say atoi, how can I find the header file I
Let's say I have a header file with a class that uses std::string .
I have a header file, lets say Common.h, that is included in all of
Let's say I have the following HTML: <table id=foo> <th class=sortasc>Header</th> </table> <table id=bar>
I have a structure Defined in the Header file for a class i am
In eclipse, whenever I create a new C++ class, or C header file, I
Is it possible to make a C++ header file (.h) that declares a class,
Don't have much to say, just can get into the event handler. XAML: <Grid>
Let's say i have a header file Snake.h: #include SnakeBodyPart.h #include GUI.h //... And
I defined a simple class. The definition is in the header file and the

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.