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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:20:25+00:00 2026-06-06T21:20:25+00:00

Suppose I have a piece of code like this: int foo(int a, int b,

  • 0

Suppose I have a piece of code like this:

int foo(int a, int b, int c)
{
    int tmp1, tmp2, tmp3;
    ...
    some_calculation0(&tmp1, a, b); // stores the result in tmp1
    some_calculation1(&tmp2, b, c);
    some_calculation2(&tmp3, tmp1, tmp2);

    return tmp3;
}

Lately I would write this as:

int foo(int a, int b, int c)
{
    int tmp[3];
    ...
    some_calculation0(&tmp[0], a, b); // stores the result in tmp[0]
    some_calculation1(&tmp[1], b, c);
    some_calculation2(&tmp[2], tmp[0], tmp[1]);

    return tmp[2];
}

Is there any reason not to do something like this? Would anyone consider it poor practice?

In this case the tmp values are really intermediate values in a string of computations, since all the functions return their result in one of the input variables passed by reference. To me it made sense to group them together, but seeing as the response so far has been against it, I have nothing against using separate variables.

  • 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-06T21:20:26+00:00Added an answer on June 6, 2026 at 9:20 pm

    This interferes with the readability of your code. Variable names should provide some information about their usage.

    While using tmp as a variable name is occasionally useful and reasonable, using an array of tmp in this way gives no indication about how the variables are being used: you’re hiding the details of your calculations behind an opaque name/structure. Furthermore I need to keep track of indices to figure out what’s going on in the code, which is confusing, and is prone to programmer error.

    It takes no more effort to pick specific variable names, and if the variables really have no better name than tmpX, then prefer common conventions, for instance, x, y, z as iterators, index or idx for indices, etc..

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

Sidebar

Related Questions

In javascript suppose you have this piece of code: <div> <script type=text/javascript>var output =
I have a piece of code looking like this: start <- getCPUTime (_, _,
Suppose I have a piece of Perl code like: foreach my $x (@x) {
I have encountered this piece of code that is supposed to determine the parent
Suppose I compile a source file file which contains this piece of code, struct
I suppose I have a straightforward question to answer. I have this piece of
I have ' inherited ' a brilliant piece of TSQL code that does this:
Suppose I have an R dataframe that looks like this, where end.group signifies the
I have a piece of js code which I would really like to improve
I have a piece of Python code that is supposed to open a new

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.